The floor() method in How to use floor method is used to round the number passed as a parameter to the nearest integer in the downward direction, that is, towards the smaller value. In this article, we will take a look at the floor() method. specific usage.
The basic syntax of the floor() method:
Math.floor( x ) ;
x represents a number and returns the largest integer less than or equal to the number x.
Let’s take a look at the specific example
The code is as follows
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script type="text/javascript"> document.write(Math.floor(-2)+"<br/>"); document.write(Math.floor(-2.56)+"<br/>"); document.write(Math.floor(2.56)+"<br/>"); document.write(Math.floor(7.2+9.3)); </script> </body> </html>
The effect of running on the browser is as follows: the output of all numbers will be less than or equal to it Maximum integer.
This article ends here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !
The above is the detailed content of How to use floor method. For more information, please follow other related articles on the PHP Chinese website!