Visit Mozilla.org

Core JavaScript 1.5 Reference:Global Objects:Math:floor

From MDC


Contents

[edit] Summary

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

Method of Math

Static

Implemented in: JavaScript 1.0, NES 2.0
ECMA Version: ECMA-262

[edit] Syntax

Math.floor(x)

[edit] Parameters

x 
A number.

[edit] Description

Because floor is a static method of Math, you always use it as Math.floor(), rather than as a method of a Math object you created.

[edit] Examples

[edit] Example: Using Math.floor

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.

[edit] See Also

ceil