The Math.ceil() function in JavaScript is used to round the number passed as parameter to its nearest integer in Upward direction of rounding i.e towards the greater value.
Syntax
Math.ceil(value)
Parameters: This functions accepts a single parameter is the number to be rounded to its
nearest integer in upward rounding method.
Returns: Result after rounding the number passed as 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 parameter returns NaN
- An array with more than 1 integer passed as parameter returns NaN
- An empty variable passed as parameter returns NaN
- An empty string passed as parameter returns NaN
- An empty array passed as parameter returns NaN
Below are some examples that illustrate the Math.ceil() function in JavaScript:
<!-- NEGATIVE NUMBER EXAMPLE --><script type="text/javascript"> document.write(Math.ceil(-2) + "<br>"); document.write(Math.ceil(-2.56)); </script> |
Output:
-2 -2
<!-- POSITIVE NUMBER EXAMPLE --><script type="text/javascript"> document.write(Math.ceil(2) + "<br>"); document.write(Math.ceil(2.56)); </script> |
Output:
2 3
<!-- STRING EXAMPLE --><script type="text/javascript"> document.write(Math.ceil("Geeksforgeeks")); </script> |
Output:
NaN
<!-- ADDITION INSIDE FUNCTION EXAMPLE --><script type="text/javascript"> document.write(Math.ceil(7+9)); </script> |
Output:
16
Supported Browsers: The browsers supported by JavaScript Math.ceil( ) function are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- JavaScript Course | Understanding Code Structure in JavaScript
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | What is JavaScript ?
- JavaScript Course | Operators in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | Variables in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- How to include a JavaScript file in another JavaScript file ?
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to Check a Function is a Generator Function or not using JavaScript ?
- JavaScript | Math.round( ) function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


