The floor() method rounds a number downwards to the nearest integer, and returns the result.
The floor() method rounds a number downwards to the nearest integer, and returns the result.
If the passed argument is an integer, the value will not be rounded.
Math.floor(x)
Parameter | Require | Description |
---|---|---|
x | Required. | The number you want to round |
A Number, representing the nearest integer when rounding downwards
Round a number downward to its nearest integer:
//round the number 1.6 downward to its nearest integer. console.log(Math.floor(1.6));/*from w ww .j a va2 s . co m*/ //Use the floor() method on different numbers: var a = Math.floor(0.60); var b = Math.floor(0.30); var c = Math.floor(2); var d = Math.floor(4.1); var e = Math.floor(-2.1); var f = Math.floor(-6.9); var x = a + "\n" + b + "\n" + c + "\n" + d + "\n" + e + "\n" + f; console.log(x);