JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

Math.floor() Function

Name

Math.floor() Function---round a number down

Availability

Navigator 2.0, Internet Explorer 3.0

Synopsis

Math.floor(x)

Arguments

x

Any numeric value or expression.

Returns

The closest integer less than or equal to x.

Description

Math.floor() computes the floor function--i.e., it returns the nearest integer value that is less than or equal to the function argument. Math.floor() rounds a floating-point value down to the closest integer. This differs from Math.round() which rounds up or down to the nearest integer. Also note that Math.floor() rounds negative numbers to be more negative, not closer to zero.

Example

a = Math.floor(1.99);  // result is 1.0
b = Math.floor(1.01);  // result is 1.0
c = Math.floor(1.0);   // result is 1.0
d = Math.floor(-1.01);  // result is -2.0

See Also

"Math", "Math.ceil()", "Math.round()"


Previous Home Next
Math.exp() Book Index Math.LN10

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell