JavaScript Math.round() Method
The Math.round() static method rounds a number to the nearest whole number. Halves round up, towards positive infinity.
Description
The Math.round() static method returns the number rounded to the nearest integer. Values exactly halfway round towards positive infinity, so Math.round(2.5) is 3 but Math.round(-2.5) is -2.
To round to a number of decimal places, multiply first: Math.round(x * 100) / 100. For displaying a fixed number of decimals, toFixed() returns a padded string.
Floating point values can make rounding to decimal places look wrong, as with Math.round(1.005 * 100) / 100 giving 1, because 1.005 is stored as slightly less. For money, working in whole cents avoids most of these problems. Intl.NumberFormat rounds correctly for display.
Syntax
Math.round(x)Parameters
- xA number.
Return Value
x rounded to the nearest integer.
Example
Browser Support
The following information will show you the current browser support for the Math.round() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





