The ceil() method rounds a number UPWARDS to the nearest integer, and returns the result.
The ceil() method rounds a number UPWARDS to the nearest integer, and returns the result.
If the passed argument is an integer, the value will not be rounded.
Math.ceil(x)
Parameter | Require | Description |
---|---|---|
x | Required. | The number you want to round |
A Number, representing the nearest integer when rounding upwards
Round a number upward to its nearest integer:
//round the number 1.4 upward to its nearest integer.
console.log(Math.ceil(1.4));
Use the ceil() method on different numbers:
The result of a,b,c,d,e, and f will be:
//round different numbers upwards to the nearest integer. var a = Math.ceil(0.20); var b = Math.ceil(0.50); var c = Math.ceil(3); var d = Math.ceil(2.1); var e = Math.ceil(-5.1); var f = Math.ceil(-4.9); var x = a + "\n" + b + "\n" + c + "\n" + d + "\n" + e + "\n" + f; console.log(x);/*from ww w .j a va2 s . c o m*/