floor

Returns the largest integer less than or equal to a number.

Applies to

Math

Syntax

floor(x)

Parameters

x

A number.

Description

floor is a static method of Math. As a result, you always use it as Math.floor(), rather than as a method of a Math object you create.

Examples

The following function returns the floor value of the variable x:

function getFloor(x) {
      return Math.floor(x)
}

If you pass 45.95 to getFloor, it returns 45; if you pass -45.95, it returns -46.

See also

Math:ceil