Math.ceil() Method in JS – How to Round Up Numbers
Whenever you invoke Math.ceil(), the method rounds up its argument to the nearest integer.
Syntax of the Math.ceil() Method
Section titled “Syntax of the Math.ceil() Method”Math.ceil() accepts only one argument. Here is the syntax:
Math.ceil(value);The value argument represents the number you wish to round up to the nearest integer.
Examples
Section titled “Examples”Below are examples of the Math.ceil() method.
Round up 9 to the nearest integer
Section titled “Round up 9 to the nearest integer”Math.ceil(9);
// The invocation above will return: 9Round up 9.999 to the nearest integer
Section titled “Round up 9.999 to the nearest integer”Math.ceil(9.999);
// The invocation above will return: 10Round up -9.999 to the nearest integer
Section titled “Round up -9.999 to the nearest integer”Math.ceil(-9.999);
// The invocation above will return: -9The snippet above returned -9 because -9 is the integer directly above -9.999 on the number line. In other words, -9 is greater than -9.999. But -10 is less than -9.999.
Round up 0.91 to the nearest integer
Section titled “Round up 0.91 to the nearest integer”Math.ceil(0.91);
// The invocation above will return: 1Round up 0.01 to the nearest integer
Section titled “Round up 0.01 to the nearest integer”Math.ceil(0.01);
// The invocation above will return: 1Round up 0 to the nearest integer
Section titled “Round up 0 to the nearest integer”Math.ceil(0);
// The invocation above will return: 0