The round() method rounds a number to the nearest integer.
The round() method rounds a number to the nearest integer.
2.49 will be rounded down, 2.5 will be rounded up.
Math.round(x)
Parameter | Require | Description |
---|---|---|
x | Required. | The number to be rounded |
A Number, representing the nearest integer
Round a number to the nearest integer:
//round the number 2.5 to its nearest integer. console.log(Math.round(2.5));/*from w w w .ja v a 2s. c om*/ //Round different numbers to the nearest integer: var a = Math.round(2.60); var b = Math.round(2.50); var c = Math.round(2.49); var d = Math.round(-1.60); var e = Math.round(-1.50); var f = Math.round(-1.49); var x = a + "\n" + b + "\n" + c + "\n" + d + "\n" + e + "\n" + f; console.log(x);