![]() |
VOOZH | about |
JavaScript Math.round( ) function is used to round the number passed as a parameter to its nearest integer.
Syntax:
Math.round(value)
Parameters:
Example 1: Rounding Off a number to its nearest integer
To round off a number to its nearest integer, the math.round() function should be implemented in the following way:
Output:
Number after rounding : 6
Example 2: Rounding Off a negative number to its nearest integer
The Math.round() function itself rounds off a negative number when passed as a parameter to it. To round off a negative number to its nearest integer, the Math.round() function should be implemented in the following way:
Output:
Number after rounding : -6
Example 3: Math.round() function, when a parameter has ".5" as a decimal
Below program shows the result of Math.round() function when the parameter has ".5" as a decimal.
Output:
Number after rounding : -12 Number after rounding : 13
We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.
Supported Browsers:
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.