Skip to content

JavaScript Math floor() | Method

  • by

JavaScript Math floor() method is used to round down a number to the next smallest integer. This function returns round a number DOWN to the nearest integer.

Math.floor(x)

If the given number is already an integer, the floor() method returns it directly.

Note: Math.floor() returns 0 for null rather than NaN.

JavaScript Math floor() Method

A simple example code decreases the given number up to the closest integer value.

<!DOCTYPE html>
<html>
<body>
  <script>
    console.log(Math.floor(5.95));

    console.log(Math.floor(5.05));

    console.log(Math.floor(5));

    console.log(Math.floor(-5.05));
  </script>
</body>
</html>

Output:

JavaScript Math floor Method

Do comment if you have any doubts or suggestions on this JS Math function topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading