Latest web development tutorials

JavaScript floor () method

Math Object Reference JavaScript Math Object

Examples

Returns the largest integer less than equal to x:

Math.floor(1.6);

The above examples will output:

1

try it"

Definition and Usage

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

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support floor () method


grammar

Math.floor( x )

Parameter Value

参数 描述
x 必需。任意数值或表达式。

return value

类型 描述
Number 小于等于 x,且与 x 最接近的整数。

technical details

JavaScript version: 1.0


More examples

Examples

In this example, we will use a different number of floor ():

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, and f output:

0
0
5
5
-6
-6

try it"


Math Object Reference JavaScript Math Object