JavaScript floor() method

Definition and usage

floor() The method rounds the number down to the nearest integer and returns the result.

If the passed parameter is an integer, the value will not be rounded.

Description

floor() The method performs a floor calculation, returning the integer that is less than or equal to the function parameter and closest to it.

Example

Example 1

Round the number down to the nearest integer:

Math.floor(1.6);

Try it yourself

Example 2

Using the floor() method on 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);

Try it yourself

Syntax

Math.floor(x)

Parameter value

Parameter Description
x Required. The number you want to round down.

Technical details

Return value: The value, representing the nearest integer when rounding down.
JavaScript Version: ECMAScript 1

Browser Support

Methods Chrome Edge Firefox Safari Opera
floor() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Math