JavaScript Math.floor() Method

Definition
Math.floor(x) rounds a number down to the previous whole number (an integer). It always moves toward negative infinity. 4.9 becomes 4.
Math is built into JavaScript. Call the method directly. It is not a constructor, so never write new Math().
Syntax
Call Math.floor() like this. Start with this line.
| Call | What it does |
|---|
Math.floor(x) | Rounds x down to the previous whole number. |
Built into JavaScript. Call Math.floor() on the Math object — no import required.
Library declarations
interface Math {
floor(x: number): number;
}
Parameters
| Parameter | Description |
|---|
| x | Required. A number. Other values are converted to a number first. |
Return Value
| Return Value | Description |
|---|
| number | The largest integer that is less than or equal to x. Returns NaN if x cannot be turned into a number. |
JavaScript Examples
Example 1 — Basic Use
Any number with a decimal part is rounded down.
console.log(Math.floor(4.9)); // 4
console.log(Math.floor(4.1)); // 4
console.log(Math.floor(4)); // 4
console.log(Math.floor(-4.1)); // -5
console.log(Math.floor(0.9)); // 0
How It Works
- Round down.
4.9 and 4.1 both go down to 4. - Whole numbers.
4 stays 4. - Negative numbers.
-4.1 moves down to -5 (further from zero). - Tiny decimals.
0.9 still rounds down to 0.
Example 2 — Split Seconds Into Minutes
Use Math.floor() to count full minutes. Use % for the seconds that are left.
var total = 135;
var minutes = Math.floor(total / 60);
var seconds = total % 60;
console.log(minutes); // 2
console.log(seconds); // 15
console.log(minutes + "m " + seconds + "s"); // 2m 15s
How It Works
- Divide.
135 / 60 is 2.25. - Floor.
Math.floor(2.25) gives 2 full minutes. - Remainder.
135 % 60 is 15 seconds left over.
Example 3 — Round Down to 2 Decimals
Multiply, floor, then divide. Watch negative numbers: floor goes down.
function floorTo2(value) {
return Math.floor(value * 100) / 100;
}
console.log(floorTo2(3.14159)); // 3.14
console.log(floorTo2(9.999)); // 9.99
console.log(floorTo2(-3.14159)); // -3.15
How It Works
- Shift.
3.14159 * 100 is 314.159. - Floor.
Math.floor(314.159) is 314. - Shift back. Divide by
100 to get 3.14. - Negative.
-3.14159 floors to -3.15, because floor goes down.
Compatibility
Browser & Runtime Support
Math.floor() has been part of JavaScript since ES1 and is Baseline Widely available everywhere.
✓ Baseline · ES1
Math.floor()
Supported in every browser and Node.js version. No polyfill is needed.
99% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full supportMath.floor Excellent
Bottom line: Use Math.floor() freely. It works in all browsers and runtimes.
Frequently Asked Questions
Math.floor(x) rounds x down to the nearest whole number. Math.floor(4.9) is 4 and Math.floor(4) is 4.
It moves away from zero. Math.floor(-4.1) is -5. Use Math.trunc(-4.1) if you want -4.
Use Math.floor(total / 60) for minutes and total % 60 for seconds. 135 seconds is 2 minutes 15 seconds.
Multiply by 100, use Math.floor(), then divide by 100. Math.floor(3.14159 * 100) / 100 is 3.14.
floor always goes down. round goes to the nearest whole number. Math.floor(4.9) is 4, but Math.round(4.9) is 5.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful