JavaScript ceil() method
- Previous Page cbrt()
- Next Page clz32()
- Go to Parent Level JavaScript Math Reference Manual
Definition and usage
ceil()
The method rounds a number up to the nearest integer and returns the result.
If the passed parameter is an integer, the value will not be rounded.
Description
ceil()
The method performs a ceiling calculation and returns an integer that is greater than or equal to the function parameter and closest to it.
Instance
Example 1
Round a number up to its nearest integer:
Math.ceil(1.4)
Example 2
Use the ceil() method for different numbers:
var a = Math.ceil(0.60); var b = Math.ceil(0.40); var c = Math.ceil(5); var d = Math.ceil(5.1); var e = Math.ceil(-5.1); var f = Math.ceil(-5.9);
The results of a, b, c, d, e, and f will be:
1 1 5 6 -5 -5
Syntax
Math.ceil(x)
Parameter value
Parameter | Description |
---|---|
x | Required. The number you want to round up. |
Technical details
Return value: | A number, representing the nearest integer when rounding up. |
---|---|
JavaScript version: | ECMAScript 1 |
Browser Support
Math.ceil()
Is an ES1 feature (JavaScript 1999). All browsers fully support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Support | Support | Support | Support | Support | Support |
Related Pages
Tutorial:JavaScript Math
- Previous Page cbrt()
- Next Page clz32()
- Go to Parent Level JavaScript Math Reference Manual