Math.round()

Returns the value of a number rounded to the nearest integer.

Since ES1 Spec ↗

Syntax

Math.round(x)

Parameters

NameTypeRequiredDescription
x number Yes The number to round.

Returns

number — The value of x rounded to the nearest integer.

Examples

console.log(Math.round(2.5), Math.round(2.4));
Output
3 2
console.log(Math.round(-2.5));
Output
-2

Notes

Ties round toward positive infinity (half-up), so `Math.round(-2.5)` is -2, not -3. This asymmetry can surprise; for banker's rounding implement it manually.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also