JavaScript Math.round()
Definition and Usage
The Math.round() method rounds a number to the nearest integer.
Note: 2.49 will be rounded down (2), and 2.5 will be rounded up (3).
Example 2
Round different numbers to the nearest integer:
let a = Math.round(2.60);
let b = Math.round(2.50);
let c = Math.round(2.49);
let d = Math.round(-2.60);
let e = Math.round(-2.50);
let f = Math.round(-2.49);
Try it Yourself »
Browser Support
Math.round()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
Math.round(x)
Parameters
Parameter | Description |
---|---|
x | Required. The number to be rounded |
Return Value
A number representing the nearest integer. |