The Wayback Machine - https://web.archive.org/web/20211221224820/https://www.geeksforgeeks.org/javascript-math-floor-method/
Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript Math floor() Method

  • Difficulty Level : Medium
  • Last Updated : 08 Jul, 2020

Below is the example of the Math floor() Method.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

  • Example:




    <script type="text/javascript">
             document.write("Result : " + Math.floor(.89));
    </script>
  • Output:
    Result : 0

The Math.floor method is used to round off the number passed as a parameter to its nearest integer in Downward direction of rounding i.e. towards the lesser value.

Syntax:

Math.floor(value)

Parameters: This method accepts single parameter asmentioned above and described below:



  • Value: It is the value which is to be tested for Math.floor.

Return Value: The Math.floor() method returns the smallest integer greater than or equal to the given number.

Below examples illustrate the Mathe floor() method in JavaScript:

  • Example 1:
    Input : Math.floor(.89)
    Output: 0
  • Example 2:
    Input :  Math.floor(-89.02)
    Output : -90
  • Example 3:
    Input : Math.floor(0)
    Output : 0

    More codes for the above method are as follows:

    Program 1: When a negative number is passed as a parameter.




    <script type="text/javascript">
             document.write("Result : " + Math.floor(-89.02));
    </script>

    Output:

    Result : -90

    Program 2: When zero is passed as a parameter.




    <script type="text/javascript">
             document.write("Result : " + Math.floor(0));
    </script>

    Output:

    Result : 0

    Supported Browsers:

    • Google Chrome
    • Internet Explorer
    • Firefox
    • Opera
    • Safari



    My Personal Notes arrow_drop_up
  • Recommended Articles
    Page :

    Start Your Coding Journey Now!