Favorites

JavaScript Math.floor() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Math.floor()
JavaScript Math Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

The Math.floor() static method rounds a number down to the nearest whole number.

Description

The Math.floor() static method always rounds down to the largest integer less than or equal to the number. For negative numbers that means away from zero, so Math.floor(-4.2) is -5; use Math.trunc() to simply drop the decimals. It's often combined with Math.random() to get random integers.

To round down to a number of decimal places, scale the number first: Math.floor(x * 100) / 100. When you need an integer index from a decimal, such as picking an array element from a random number, Math.floor() guarantees a valid position from 0 to length - 1.

Like every member of Math, it's called on the Math object itself rather than on a number, and it only works with the Number type: passing a BigInt throws a TypeError.

Syntax

Math.floor(x)

Parameters

  • xA number.

Return Value

The largest integer less than or equal to x.

Example

console.log(Math.floor(4.9));
console.log(Math.floor(-4.2));
console.log(Math.trunc(-4.2));
console.log(Math.floor(Math.random() * 10));

Browser Support

The following information will show you the current browser support for the Math.floor() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee