JavaScript Math.ceil( ) function

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

Returns: 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: 

Below are some examples that illustrate the Math.ceil() function in JavaScript:
 Example: 1 






<!-- NEGATIVE NUMBER EXAMPLE -->
<script type="text/javascript">
    console.log(Math.ceil(-2) + "<br>");
    console.log(Math.ceil(-2.56));        
</script>

Output: 

-2
-2

Example:2




<!-- POSITIVE NUMBER EXAMPLE -->
<script type="text/javascript">
    console.log(Math.ceil(2) + "<br>");
    console.log(Math.ceil(2.56));        
</script>

Output: 

2
3

Example :3




<!-- STRING EXAMPLE -->
<script type="text/javascript">
    console.log(Math.ceil("Geeksforgeeks"));        
</script>

Output: 

NaN

Example:4




<!-- ADDITION INSIDE FUNCTION EXAMPLE -->
<script type="text/javascript">
    console.log(Math.ceil(7+9));        
</script>

Output: 

16

Supported Browsers: The browsers supported by JavaScript Math.ceil( ) function are listed below: 


Article Tags :