Math.ceil()
Rounds a number up to the next largest integer.
Syntax
Math.ceil(x) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
x | number | Yes | The number to round up. |
Returns
number — The smallest integer greater than or equal to x.
Examples
console.log(Math.ceil(4.1), Math.ceil(4.0));
Output
5 4
console.log(Math.ceil(-4.7));
Output
-4
Notes
Rounds toward positive infinity, so `Math.ceil(-4.7)` is -4. Returns a number
even if the result is integral. Contrast with `floor` and `trunc`.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |