JavaScript (ES2026) reference · Math Methods and Constants
JavaScript Math.round() Method
Round a number to the nearest integer; halves round up towards +Infinity, so Math.round(-2.5) is -2.
JavaScript (ES2026) Since ES1
Syntax
Math.round(x)
Parameters
| Parameter | Description |
|---|---|
x |
A number. |
Return value
An integer.
Examples
console.log(Math.round(2.5), Math.round(2.4), Math.round(-2.5), Math.round(-2.6));
Output
3 2 -2 -3
const price = 19.996;
console.log(Math.round(price * 100) / 100, price.toFixed(2));
Output
20 20.00
Version history
| Version | Change |
|---|---|
| JavaScript ES1 | Added |
In other languages
round()· Python
Related
Math.floor()· Round a number down to the integer below it: Math.floor(4.9) is 4 and Math.floor(-4.1) is -5.Math.ceil()· Round a number up to the next integer: Math.ceil(4.1) is 5 and Math.ceil(-4.1) is -4.Math.trunc()· Remove the fractional part of a number, rounding towards zero: Math.trunc(-4.7) is -4.number.toFixed()· Format a number with a fixed number of decimal places, returned as a string. Rounds, but floating-point quirks apply.- JavaScript Math · tutorial
- JavaScript Numbers · tutorial