The Math.ceil()
static method always rounds up and returns the smallest integer greater than or equal to a given number.
The Math.ceil()
static method always rounds up and returns the smallest integer greater than or equal to a given number.
Math.ceil(x)
x
A number.
The smallest integer greater than or equal to x
. It's the same value as -Math.floor(-x)
.
Because ceil()
is a static method of Math
, you always use it as Math.ceil()
, rather than as a method of a Math
object you created (Math
is not a constructor).
Math.ceil(-Infinity); // -Infinity Math.ceil(-7.004); // -7 Math.ceil(-4); // -4 Math.ceil(-0.95); // -0 Math.ceil(-0); // -0 Math.ceil(0); // 0 Math.ceil(0.95); // 1 Math.ceil(4); // 4 Math.ceil(7.004); // 8 Math.ceil(Infinity); // Infinity
Specification |
---|
ECMAScript Language Specification # sec-math.ceil |
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | Deno | Node.js | ||
ceil |
1 | 12 | 1 | 3 | 1 | 18 | 4 | 10.1 | 1 | 1.0 | 4.4 | 1.0 | 0.10.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil