Math.round() / floor() / ceil()
method
round() rounds to nearest integer; floor() rounds down; ceil() rounds up.
Syntax
Math.round(x) Math.floor(x) Math.ceil(x)
Example
javascript
Math.round(4.5); // 5
Math.round(4.4); // 4
Math.floor(4.9); // 4 (always down)
Math.ceil(4.1); // 5 (always up)
// Round to 2 decimal places
Math.round(3.14159 * 100) / 100; // 3.14
// Truncate (toward zero)
Math.trunc(4.9); // 4
Math.trunc(-4.9); // -4