Skip to main content

ceil()

ceil(n, precision?): number

Computes number rounded up to precision.

DEPRECATED

Use Math.ceil() directly instead.


Parameters​

n: number​

The number to round up.

precision?: number = 0​

The precision to round up to. Defaults to 0.


Returns: number​

The rounded up number.


See Also​

Math.ceil() - MDN


Since​

2.0.0


Also known as​

ceil (Lodash, es-toolkit) · ❌ (Remeda, Radashi, Ramda, Effect, Modern Dash, Antfu)


Example​

// ❌ Deprecated approach
ceil(4.006); // => 5
ceil(6.004, 2); // => 6.01
ceil(6040, -2); // => 6100

// βœ… Recommended approach
Math.ceil(4.006); // => 5
Math.ceil(6.004 * 100) / 100; // => 6.01
Math.ceil(6040 / 100) * 100; // => 6100

How it works?​

Rounds number up to specified precision. Deprecated: Use Math.ceil() directly.

Native Equivalent​

// ❌ ceil(value)
// βœ… Math.ceil(value)

Use Cases​

Round up πŸ“Œβ€‹

Round number up to nearest integer.

Math.ceil(4.1);   // 5
Math.ceil(-4.9); // -4

Calculate pages​

Calculate total pages needed.

const totalPages = Math.ceil(items.length / pageSize);