Javascript - Math floor() Method

The floor() method rounds a number downwards to the nearest integer, and returns the result.

Description

The floor() method rounds a number downwards to the nearest integer, and returns the result.

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

Syntax

Math.floor(x)

Parameter Values

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

Return

A Number, representing the nearest integer when rounding downwards

Example

Round a number downward to its nearest integer:

Demo

//round the number 1.6 downward to its nearest integer.
console.log(Math.floor(1.6));//from  www . j av  a 2  s . c om

//Use the floor() method on different numbers:
var a = Math.floor(0.60);
var b = Math.floor(0.30);
var c = Math.floor(2);
var d = Math.floor(4.1);
var e = Math.floor(-2.1);
var f = Math.floor(-6.9);

var x = a + "\n" + b + "\n" + c + "\n" + d + "\n" + e + "\n" + f;
console.log(x);

Result