How to Round Down a Number in JavaScript


Borislav Hadzhiev

Wed Oct 27 20211 min read

Round Down a Number in JavaScript #

To round down a number, pass it to the Math.floor() function, e.g. Math.floor(5.5). The Math.floor function returns a number that represents the largest integer that is less than or equal to the provided number.

console.log(Math.floor(3.99)); // 👉️ 3 console.log(Math.floor(3.009)); // 👉️ 3 console.log(Math.floor(-3.01)); // 👉️ -4 console.log(Math.floor(-3.99)); // 👉️ -4 console.log(Math.floor(null)); // 👉️ 0

We used the Math.floor function to round a number down.

The function rounds numbers with a fractional part to the largest integer that is less than the passed in number.

If the number is an integer, it gets returned as is.

console.log(Math.floor(5)); // 👉️ 5 console.log(Math.floor(-55)); // 👉️ -55

In other words, the function rounds towards negative infinity.

Note that the Math.floor function returns 0 if you pass it a null value.

Further Reading #

Use the search field on my Home Page to filter through my more than 1,000 articles.