Math.round()

Math.round(x) → number

Returns the value of x rounded to the nearest integer.

Rounds x to the nearest integer. Values with a fractional part of exactly 0.5 are rounded up toward positive infinity, so Math.round(-2.5) returns -2.

Arguments

NameTypeRequiredDefaultDescription
x number optional — A number.

Returns

number x rounded to the nearest integer.

Example

let r = Math.round(4.5); // 5