JavaScript Math.floor method
The Math.floor method is used to round down the numeric value, that is, to obtain the maximum integer less than or equal to the numeric value. The syntax is as follows:
Math.floor(x)
Parameter description:
| parameter | illustrate |
|---|---|
| x | Required. Must be a numeric value. |
Tip: This method is exactly the opposite of the Math.ceil method.
Math.floor method example
<script language="JavaScript">document.write( Math.floor(0.35) + "<br />" );document.write( Math.floor(10) + "<br />" );document.write( Math.floor(-10) + "<br />" );document.write( Math.floor(-10.1) );</script>
Run this example and output:
0
10
-10
-11
Math.floor may not be accurate
If the parameter x is an expression involving floating point numbers, the results of the expression after applying the Math.floor method may be inaccurate (unreasonable) due to the inherent principles of the computer. For details, please refer to the relevant description in the article "Math.ceil Method".