JavaScript Tutorial JavaScript References

JavaScript - Math.floor() Method



The JavaScript Math.floor() method returns the next lowest integer value by rounding down the specified number, if necessary. In other words, it rounds the fraction DOWN of the given number.

Syntax

Math.floor(x)

Parameters

x Specify a number.

Return Value

Returns the next lowest integer value by rounding DOWN the specified number, if necessary.

Example:

In the example below, Math.floor() method is used to round the fraction DOWN of the specified number.

var txt;

txt = "Math.floor(10.5) = " + Math.floor(10.5) + "<br>";
txt = txt + "Math.floor(-10.5) = " + Math.floor(-10.5) + "<br>";
txt = txt + "Math.floor(0.5) = " + Math.floor(0.5) + "<br>";
txt = txt + "Math.floor(-0.5) = " + Math.floor(-0.5) + "<br>";

The output (value of txt) after running above script will be:

Math.floor(10.5) = 10
Math.floor(-10.5) = -11
Math.floor(0.5) = 0
Math.floor(-0.5) = -1

❮ JavaScript - Math Object