Math.round Examples
The general syntax for this method is:
Math.round(number)
This method returns number rounded to the nearest integer value.
Numerical strings can also be evaluated, but should be avoided as a best practice.
Example
| |
Console Output
1
-29
9
101
Math.round also works on arrays, but must be combined with the
map array method. The syntax for this is:
arrayName.map(Math.round)
Example
| |
Console Output
[ 1, 4, 9, -16, 8 ]