Parameters: This method accepts a single parameter as mentioned above and described below
- value: It is the number that you want to round off.
Return Value: The Math.round() method returns the value of the given number rounded to the nearest integer.
Below is an example of the Math round() Method.
Example: To round off a number to its nearest integer.
Number after rounding : 6
Program 1: The Math.round() method 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() method should be implemented in the following way:
Number after rounding : -6
Program 2: Below program shows the result of the Math.round() method when the parameter has “.5” in decimal.
Number after rounding : -12 Number after rounding : 13
- Google Chrome
- Internet Explorer