JS: Math ceiling, floor, round, truncate

By Xah Lee. Date: . Last updated: .
Math.ceil(x)

Return a integer that's equal or greater than x.

console.log(Math.ceil(1.3));
// 2

console.log(Math.ceil(-0.5));
// -0
ceiling 2026-06-28 2c2d4 ll
ceiling 2026-06-28 2c2d4 ll
Math.floor(x)

Return a integer that's equal or less than x.

Math.round(x)

Return a number to the nearest integer.

0.5 rounds up to 1.

console.log(Math.round(1.3));
// 1

console.log(Math.round(1.49999));
// 1

console.log(Math.round(1.5));
// 2

console.log(Math.round(-0.3));
// -0

console.log(Math.round(-0.5));
// -0

console.log(Math.round(-0.6));
// -1
Math.trunc(x)

(new in ECMAScript 2015)

Return the integral part of x.

console.log(Math.trunc(1.3));
// 1

console.log(Math.trunc(0.5));
// 0

console.log(Math.trunc(-0.5));
// -0

JavaScript. format number

JavaScript. math functions.