The Wayback Machine - https://web.archive.org/web/20240118174210/https://www.geeksforgeeks.org/javascript-math-ceil-function/
Open In App
Related Articles

JavaScript Math.ceil( ) function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Math.ceil() function in JavaScript is used to round the number passed as a parameter to its nearest integer in an Upward direction of rounding i.e. towards the greater value.

Syntax:

Math.ceil(value);

Parameters:

This function accepts a single parameter as the number to be rounded to its nearest integer in the upward rounding method. 

Return Value:

Result after rounding the number passed as a parameter to the function.

Examples: 

Input  : Math.ceil(4.23)
Output : 5
Input : Math.ceil(0.8)
Output : 1

Errors and Exceptions: 

  • A non-numeric string passed as a parameter returns NaN.
  • An array with more than 1 integer passed as a parameter returns NaN.
  • An empty variable passed as a parameter returns NaN.
  • An empty string passed as a parameter returns NaN.
  • An empty array passed as a parameter returns NaN.

 Example 1: In this example, we have used Math.ceil function.

Javascript




<!-- NEGATIVE NUMBER EXAMPLE -->
console.log(Math.ceil(-2));
console.log(Math.ceil(-2.56));


Output

-2
-2

Example 2: In this example, we have used Math.ceil function.

Javascript




<!-- POSITIVE NUMBER EXAMPLE -->
console.log(Math.ceil(2));
console.log(Math.ceil(2.56));


Output

2
3

 Example 3: In this example, we have used Math.ceil function.

Javascript




console.log(Math.ceil("Geeksforgeeks"));       


Output

NaN

Example 4: In this example, we have used Math.ceil function.

Javascript




<!-- ADDITION INSIDE FUNCTION EXAMPLE -->
console.log(Math.ceil(7+9));


Output

16

Supported Browsers:

  • Google Chrome 1 and above
  • Internet Explorer 12 and above
  • Firefox 1 and above
  • Opera 3 and above
  • Safari 1 and above

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 08 Dec, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials