English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Math.round() Method

 JavaScript Math Object

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.

Syntax:

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);   // -21
Test See‹/›

Browser Compatibility

All browsers fully support the Math.round() method:

Method
Math.round()YesYesYesYesYes

Parameter Value

ParameterDescription
xThe number to be rounded

Technical Details

Return Value:Round the value of a given number to the nearest integer
JavaScript Version:ECMAScript 1

 JavaScript Math Object