Math.ceil()
Math.ceil(x)
Returns the smallest integer that is greater than or equal to x – it always rounds up.
Parameters
- x – a number.
Return value
An integer.
Examples
console.log(Math.ceil(4.1), Math.ceil(4), Math.ceil(-4.9));
const articles = 47;
const perPage = 10;
console.log('Pages:', Math.ceil(articles / perPage));
console.log('Boxes of 6:', Math.ceil(20 / 6));
Output:
5 4 -4 Pages: 5 Boxes of 6: 4
Things to watch out for
- For negative numbers it rounds towards zero (up):
Math.ceil(-4.9)is-4. - To round to decimal places use
Math.ceil(x * 100) / 100(with the inexactness of decimal numbers).
Browser support
Baseline – widely available: works in all major browsers and has for a long time (since 2015 at the latest). Since version: Chrome 1, Firefox 1, Safari 1; Node.js 0.10.0. As of October 2026 (MDN browser-compat-data).