JavaScript floor()Method

Math 对象参考手册JavaScript Math Object

Example

Returns the largest integer less than or equal to x:

Math.floor(1.6);

The above example will output:

1

Try it yourself »

Definition and Usage

The floor() method returns the largest integer less than or equal to x.

If the passed argument is an integer, the value remains unchanged.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the floor() method


Syntax

Math.floor(x)

Parameter Values

Parameter Description
x Required. Any numeric value or expression.

Return Value

Type Description
Number The integer less than or equal to x and closest to x.

Technical Details

JavaScript Version: 1.0


More Examples

Example

In this example, we will apply floor() to different numbers:

var a=Math.floor(0.60);
var b=Math.floor(0.40);
var c=Math.floor(5);
var d=Math.floor(5.1);
var e=Math.floor(-5.1);
var f=Math.floor(-5.9);

a,b,c,d,e, andfOutput:

0
0
5
5
-6
-6

Try it yourself »


Math 对象参考手册JavaScript Math Object

Other Extensions