English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Math.round()The method returns the value rounded to the nearest integer.
If the decimal part of the parameter is greater than 0.5then the parameter will be rounded to the next integer with a higher absolute value.
If less than 0.5to the nearest integer with the smaller absolute value.
For example, round3.4Round (3,3.6Round (4)
If the decimal part is exactly 0.5then the parameter will be rounded along+∞round in the direction of the next integer.
Since round() is a static method of Math, you always use it asMath.round(),not used as a method of creating the Math object.
Math.round(x)
Math.round(3.4); // 3 Math.round(3.5); // 4 Math.round(3.6); // 4 Math.round(-20.2); // -20 Math.round(-20.8); // -21Test See‹/›
All browsers fully support the Math.round() method:
Method | |||||
Math.round() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
x | The number to be rounded |
Return Value: | Round the value of a given number to the nearest integer |
---|---|
JavaScript Version: | ECMAScript 1 |