The
Math.round()
method returns a value rounded to the nearest whole number.
Description
The
round()
static method of the
Math
object rounds a number to the nearest whole number. If the part after the decimal point is more than 0.5, it rounds up to the next whole number. If the part after the decimal point is less than 0.5, it rounds down to the current whole number. When the part after the decimal point is exactly 0.5, it rounds up (towards the larger whole number).
Parameters
Number
— A numeric value whose rounded value will be returned.
Return Type
A
Number
or
Nan
.
Examples
// Sample JavaScript
Math.round(42.5); // 43
Math.round(42.4); // 42
Math.floor(42.5); // 42
Math.ceil(42.4); // 43
See Also
Math.ceil()
— Always rounds upMath.floor()
— Always rounds down- Number.toFixed()— Value with the specified number of decimal places.
- Number.toPrecision()— Value to specified number of significant digits.
Full Developer Reference
Attribution
- "Original Content" by Mozilla Contributors, licensed under CC-BY-SA 2.5 | Modified from the Original