JS: Math ceiling, floor, round, truncate
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 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.
- JS: Math (namespace)
- JS: Math. max, min
- JS: Math. sign, abs
- JS: Math ceiling, floor, round, truncate
- JS: Math. random
- JS: Power and Roots
- JS: Math exponential and logarithm
- JS: Math constants. pi, e, sqrt, etc.
- JS: Math trig functions. sin, cos, tan, asin, acos, atan
- JS: Math hyperbolic functions. sinh, cosh, tanh, etc.
- JS: Math fround, clz32, imul