JavaScript Math.floor() Method
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
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.
Desktop





Tablets & Mobile





