JavaScript Math floor() Method
The Math.floor() method in JavaScript is used to round off a number down to the nearest integer, moving towards the lower value. This function is useful when you want to ensure that the result is always rounded down, regardless of whether the number is positive or negative.
Syntax
Math.floor( value );
console.log("Floor Value of 5.89 is: ", Math.floor(5.89));
console.log("Floor Value of 5.19 is: ", Math.floor(5.19));
Output
Floor Value of 5.89 is: 5 Floor Value of 5.19 is: 5
Parameters: Math.floor() method accepts a single numeric argument.
- value: The value that is to be tested for Math.floor() method.
Return Value: The Math.floor() method returns the smallest integer less than or equal to the given number.
Example 1: Round off the negative number to smaller integer.
console.log("Floor Value of -89.02 is: ", Math.floor(-89.02));
Output
Floor Value of -89.02 is: -90
Note: The Math.floor() method does not work on integer value, it only works on float values.
We have a complete list of JavaScript Math methods, to check those please go through this JavaScript Math Object Complete reference article.
Supported Browsers