Returns the value of a number rounded to the nearest integer.
- value (float) (Required): The decimal number you wish to round off.
Return Value(s)Returns the rounded number.
If the fractional portion of the value is greater than 0.5, the value is rounded to the next integer. If it is less than 0.5, the argument is rounded to the lower integer. If the fractional portion is exactly 0.5, the argument is rounded to the next integer in the direction of +∞. This differs from some other languages’ round() functions, which often round to the next integer away from zero, instead giving a different result in the case of negative numbers with a fractional part of exactly 0.5.
Examples of Math.round()
The above will output 2.
The above will output 69.
Example 3: Use Math.round to Round to 2 Decimal Places
console.log(Math.round(68.7654* 100) / 100)
The above code will output 68.77. To round to 3 digits, for example, replace 100 with 1000.
Similar Functions in Other Languages
- PHP: round()