Home >>JavaScript Math Reference >JavaScript floor () Method

JavaScript floor () Method

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 Values

Parameter Description
x It required the number you want to round.

Browser Support

Method Chrome Edge Firefox Safari Opera
floor() Yes Yes Yes Yes Yes
Here is an example of JavaScript floor() Method
<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>
Output:

Example 2:
<html>
<body>
<script>
document.write(Math.floor(-5) + "<br>"); 
document.write(Math.floor(-6.66));		 
</script> 
</body>
</html>
Output:

No Sidebar ads