Open In App

JavaScript Math.ceil( ) function

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: 

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




<!-- 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.




<!-- 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.




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

Output
NaN

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




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

Output
16

Supported Browsers:


Article Tags :