Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript floor() Method

JavaScript floor() Method

Math Object Reference JavaScript Math object

Example

Return the largest integer less than or equal to x:

Math.floor(1.6);

The above example will output:

1

Try it »


Definition and Usage

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

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


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the floor() method


Syntax

Math.floor(

x

)

Parameter value

Parameters Description
x Required. Any numeric value or expression.

Return Value

Type Description
Number The integer that is 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, and LinkedHashMap, among others. f Output result:

0

0

5

5

-6

-6

Try it »


Math Object Reference JavaScript Math object