JavaScript Math.floor() 方法

定义和用法:

floor() 方法可对一个数进行下舍入。

语法:

Math.floor(x);

x:必须参数,可以是任意数值或表达式;

返回值:

小于等于 x,且与 x 最接近的整数。

说明:

floor() 方法执行的是向下取整计算,它返回的是小于或等于函数参数,并且与之最接近的整数。

示例代码:

 1 //在本例中,我们将在不同的数字上使用 floor() 方法:
 2 
 3 <script type="text/javascript">
 4 document.write(Math.floor(0.60) + "<br />")
 5 document.write(Math.floor(0.40) + "<br />")
 6 document.write(Math.floor(5) + "<br />")
 7 document.write(Math.floor(5.1) + "<br />")
 8 document.write(Math.floor(-5.1) + "<br />")
 9 document.write(Math.floor(-5.9))
10 </script>
11 
12 预计输出:
13 0
14 0
15 5
16 5
17 -6
18 -6
19 
20 实际效果:
21 0
22 0
23 5
24 5
25 -6
26 -6
代码
热心技术,并兼吃喝,偶谈风月,不言国事.
原文地址:https://www.cnblogs.com/baby-zhude/p/4122818.html