Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Math.ceil

Rounds a number up to an integer.

Available since: ES1

Syntax

Math.ceil(x)

Parameters

ParameterTypeDescription
xnumberThe number to round.

Return value

numberThe nearest integer greater than or equal to x.

Examples

Rounding up:

console.log(Math.ceil(4.1));
console.log(Math.ceil(4));

Output:

5
4

How many pages are needed for 23 items, 10 per page:

const items = 23;
const perPage = 10;
 
console.log(Math.ceil(items / perPage));

Output:

3

Notes

For negative numbers up means towards zero: Math.ceil(-4.7) is -4.

See also

  • Math.floor — Rounds a number down to an integer.
  • Math.round — Rounds a number to the nearest integer.
  • Math.trunc — Drops the fractional part of a number.

Related recipes

In the tutorial

  • Numbers — Numbers in JavaScript — integers and fractions, rounding, the Math object, toFixed and the special values Infinity and NaN.

Thanks for reading!

Donate to the site — we work hard for you.