Math.floor()
Rounds a number down to the largest integer less than or equal to it.
Syntax
Math.floor(x) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
x | number | Yes | The number to round down. |
Returns
number — The largest integer less than or equal to x.
Examples
console.log(Math.floor(4.7), Math.floor(4.0));
Output
4 4
console.log(Math.floor(-4.1));
Output
-5
Notes
Rounds toward negative infinity, so `Math.floor(-4.1)` is -5. For truncation
toward zero use `Math.trunc` instead.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |