rounding

Math.ceil

Returns the smallest integer greater than or equal to a given number (rounds toward +Infinity). Always moves right on the number line.

Math.ceil(x)

Parameters & edge cases

Case Behavior
x The number to ceil; non-numeric input is coerced
negative values Ceils TOWARD zero: Math.ceil(-2.9) === -2 (not -3)
-0 handling Math.ceil(-0.5) returns -0, preserving the negative sign

Examples

console.log(Math.ceil(2.1));   // 3

Any positive fraction rounds up to the next integer.

console.log(Math.ceil(-2.9));  // -2

For negatives, ceil moves toward zero, opposite of floor.

console.log(Math.ceil(5));     // 5

Integer inputs return unchanged.

console.log(Math.ceil(1/0));   // Infinity

Infinity is returned as-is.

Gotcha

For pagination: Math.ceil(total / perPage) is the correct pattern; using Math.round leaves the last partial page unreachable.

Related

← All JS Math methods · Array methods