JavaScript (ES2026) reference · Math Methods and Constants
JavaScript Math.floor() Method
Round a number down to the integer below it: Math.floor(4.9) is 4 and Math.floor(-4.1) is -5.
JavaScript (ES2026) Since ES1
Syntax
Math.floor(x)
Parameters
| Parameter | Description |
|---|---|
x |
A number. |
Return value
An integer.
Examples
console.log(Math.floor(4.9), Math.floor(-4.1));
Output
4 -5
const seconds = 3725;
console.log(`${Math.floor(seconds / 3600)}h ${Math.floor((seconds % 3600) / 60)}m ${seconds % 60}s`);
Output
1h 2m 5s
Version history
| Version | Change |
|---|---|
| JavaScript ES1 | Added |
Related
Math.ceil()· Round a number up to the next integer: Math.ceil(4.1) is 5 and Math.ceil(-4.1) is -4.Math.trunc()· Remove the fractional part of a number, rounding towards zero: Math.trunc(-4.7) is -4.Math.round()· Round a number to the nearest integer; halves round up towards +Infinity, so Math.round(-2.5) is -2.- JavaScript Math · tutorial
- JavaScript Numbers · tutorial