How can I round down a number in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The Math.floor() method returns the value of a number rounded downwards to the nearest integer.

Example

You can try to run the following code to round down numbers −

Live Demo

<html>
   <head>
      <title>JavaScript Math floor() Method</title>
   </head>
   <body>
      <script>
         var value = Math.floor( 2.7 );
         document.write("First Test Value : " + value );

         var value = Math.floor( 20.9 );
         document.write("<br />Second Test Value : " + value );

         var value = Math.floor( 15.4 );
         document.write("<br />Third Test Value : " + value );
      </script>
   </body>
</html>

Output

First Test Value : 2
Second Test Value : 20
Third Test Value : 15
raja
Published on 03-Feb-2018 16:53:07
Advertisements