This JavaScript tutorial explains how to use the math function called ceil() with syntax and examples. Show
DescriptionIn JavaScript, ceil() is a function that is used to return the smallest integer value that is greater than or equal to a number. In other words, the ceil() function rounds a number up and returns an integer value. Because the ceil() function is a static function of the Math object, it must be invoked through the placeholder object called Math. SyntaxIn JavaScript, the syntax for the ceil() function is: Math.ceil(number); Parameters or ArgumentsnumberThe number used to find the smallest integer.ReturnsThe ceil() function returns the smallest integer value that is greater than or equal to a number. Note
ExampleLet's take a look at an example of how to use the ceil() function in JavaScript. For example:
In this example, we have invoked the ceil() function using the Math class. We have written the output of the ceil() function to the web browser console log, for demonstration purposes, to show what the ceil() function returns. The following will be output to the web browser console log: 33 9 -4 In this example, the first output to the console log returned 33 which is 32.65 rounded up to an integer value. The second output to the console log returned 9 which is 8.1 rounded up to an integer value. The third output to the console log returned -4 which is -4.2 rounded up to an integer value. Notice that when dealing with negative numbers, the ceil() function rounds up towards zero and in this case, returned -4 and not -5. Returns the smallest integer greater than or equal to the given value. The result is a decimal data type.Syntax
InputArgumentTypeDescription Return ValueReturns a decimal value corresponding to the smallest integer greater than or equal to If Sample Usage<table cols="int_value,dec_value" types="i,f"> 1,-5.25; 2,5.0; 3,13; 4,4.5; 5,5.0; </table> <willbe name="ceil_int_example" value="ceil(int_value)"/> <willbe name="ceil_dec_example" value="ceil(dec_value)"/> <colord cols="int_value,ceil_int_example,dec_value,ceil_dec_example"/> ExampleIn this example, the <table cols="int_value,dec_value" types="i,f"> 1,-5.25; 2,5.0; 3,13; 4,4.5; 5,5.0; </table> <willbe name="ceil_int_example" value="ceil(int_value)"/> <willbe name="ceil_dec_example" value="ceil(dec_value)"/> <colord cols="int_value,ceil_int_example,dec_value,ceil_dec_example"/>1 column on the <table cols="int_value,dec_value" types="i,f"> 1,-5.25; 2,5.0; 3,13; 4,4.5; 5,5.0; </table> <willbe name="ceil_int_example" value="ceil(int_value)"/> <willbe name="ceil_dec_example" value="ceil(dec_value)"/> <colord cols="int_value,ceil_int_example,dec_value,ceil_dec_example"/>2 table. The new column contains decimal data type values. The Try itSyntax
Parameters
A number. Return valueThe smallest integer greater than or equal to DescriptionBecause Which function returns the smallest integer value greater than or equal to the input number?The ceil() function computes the smallest integer that is greater than or equal to x.
What method in JavaScript that returns the smallest integer greater than or equal to a decimal number?To get the smallest integer greater than or equal to a number, use the JavaScript Math. ceil() method. This method returns the smallest integer greater than or equal to a given number.
Which of the following number method returns the smallest integer that is greater than or equal to the argument in Java?Java - ceil() Method
The method ceil gives the smallest integer that is greater than or equal to the argument.
What is the smallest integer greater?The smallest integer greater than every negative integer is 0 .
|