Math.floor()

Rounds a number down to the largest integer less than or equal to it.

Since ES1 Spec ↗

Syntax

Math.floor(x)

Parameters

NameTypeRequiredDescription
x number Yes The number to round down.

Returns

number — The largest integer less than or equal to x.

Examples

console.log(Math.floor(4.7), Math.floor(4.0));
Output
4 4
console.log(Math.floor(-4.1));
Output
-5

Notes

Rounds toward negative infinity, so `Math.floor(-4.1)` is -5. For truncation toward zero use `Math.trunc` instead.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also