Home >>JavaScript Math Reference >JavaScript floor () Method
The JavaScript math. floor() method is used to round off a floating point number as a parameter to its nearest integer in downward direction. And if in case, the given number is already in an integer, this method returns the same.
Syntax:Math. Floor (value)
Parameter | Description |
---|---|
x | It required the number you want to round. |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
floor() | Yes | Yes | Yes | Yes | Yes |
<html> <body> <button onclick="myFloor()">Click me</button> <p id="floor"></p> <script> function myFloor() { document.getElementById("floor").innerHTML = Math.floor(2.5); } </script> </body> </html>
<html> <body> <script> document.write(Math.floor(-5) + "<br>"); document.write(Math.floor(-6.66)); </script> </body> </html>