Definition and Usage:
The floor () method can be rounded down by a number.
Grammar:
Math.floor (x);
X: The required parameter, which can be any number or expression;
return value:
The integer that is less than or equal to x and closest to X.
Description
The floor () method performs a down-rounding calculation, which returns an integer that is less than or equal to the function parameter and closest to it.
Example code:
1 //In This example, we will use the floor () method on different numbers:2 3<script type= "Text/javascript" >4document.write (Math.floor (0.60) + "<br/>")5document.write (Math.floor (0.40) + "<br/>")6document.write (Math.floor (5) + "<br/>")7document.write (Math.floor (5.1) + "<br/>")8document.write (Math.floor ( -5.1) + "<br/>")9document.write (Math.floor (-5.9))Ten</script> One A Expected output: -0 -0 the5 -5 --6 --6 + - Actual effect: +0 A0 at5 -5 --6 --6
Code
JavaScript Math.floor () method