JavaScript Math.floor() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

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.

JavaScript
Math.floor(x)
CallWhat 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
JavaScript
Math.floor(x)
JavaScript
interface Math {
  floor(x: number): number;
}

Parameters

ParameterDescription
xRequired. A number. Other values are converted to a number first.

Return Value

Return ValueDescription
numberThe 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.

JavaScript
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
Try It Yourself

How It Works

  1. Round down. 4.9 and 4.1 both go down to 4.
  2. Whole numbers. 4 stays 4.
  3. Negative numbers. -4.1 moves down to -5 (further from zero).
  4. 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.

JavaScript
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
Try It Yourself

How It Works

  1. Divide. 135 / 60 is 2.25.
  2. Floor. Math.floor(2.25) gives 2 full minutes.
  3. 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.

JavaScript
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
Try It Yourself

How It Works

  1. Shift. 3.14159 * 100 is 314.159.
  2. Floor. Math.floor(314.159) is 314.
  3. Shift back. Divide by 100 to get 3.14.
  4. Negative. -3.14159 floors to -3.15, because floor goes down.

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 support
Math.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.

Next: fround()

Learn how to round to the nearest 32-bit float.

fround() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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