The Wayback Machine - https://web.archive.org/web/20250108181517/https://www.geeksforgeeks.org/javascript-math-floor-method/
Open In App

JavaScript Math floor() Method

Last Updated : 07 Nov, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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 );
JavaScript
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.

JavaScript
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

JavaScript Math floor() Method – FAQs

What does the Math.floor() method do in JavaScript?

The Math.floor() method rounds a number down to the nearest integer less than or equal to the given number.

Can Math.floor() handle negative numbers?

Yes, Math.floor() can handle negative numbers. It rounds negative numbers down (away from zero) to the nearest integer less than or equal to the given number.

How does Math.floor() handle non-numeric arguments?

If the argument is not a number, Math.floor() first converts it to a number before performing the rounding operation. If the argument cannot be converted to a number, the result is NaN (Not-a-Number).

Does Math.floor() work with very large or very small numbers?

Yes, Math.floor() works with very large or very small numbers, rounding them down to the nearest integer within the limits of JavaScript’s number precision.

What is the most common use of the Math.floor() method?

Most Common Use Cases:

  • Rounding down numerical results to the nearest whole number for presentation or further calculation.
  • Ensuring non-positive integer values in algorithms that require such numbers.
  • Simplifying numerical data for readability and reporting.

Next Article

Similar Reads

three90RightbarBannerImg