The Math.round()
method is a standard round function.
Math.round()
rounds up if the number is at least
halfway to the next integer value (0.5 or higher)
and rounds down if not.
2.49 will be rounded down, 2.5 will be rounded up.
round() |
Yes | Yes | Yes | Yes | Yes |
Math.round(x);
Parameter | Description |
---|---|
x | Required. The number to round |
A number representing the nearest integer.
console.log(Math.round(25.9)); //26
console.log(Math.round(25.5)); //26
console.log(Math.round(25.1)); //25
The code above generates the following result.