Home > Web Front-end > JS Tutorial > How to use floor method

How to use floor method

不言
Release: 2019-04-24 16:28:14
Original
3544 people have browsed it

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.

How to use floor method

The basic syntax of the floor() method:

Math.floor( x ) ;
Copy after login

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>
Copy after login

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.

How to use floor method

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template