JavaScript Math floor()

The Math.floor() function rounds down a number to the next smallest integer.

Example


Math.floor() Syntax

The syntax of the Math.floor() function is:

Math.floor(x)

floor(), being a static method, is called using the Math class name.


Math.floor() Parameters

The Math.floor() function takes in:

  • x - A number

Math.floor() Return Value

  • Returns the largest integer less than or equal to a given number.
  • Returns 0 for null.

Example: Using Math.floor()

Output

1
-1
4
0
NaN
NaN

Note: Math.floor() returns 0 for null rather than NaN.


Recommended readings: