向下取整floor() |
floor() 方法可对一个数进行向下取整。 |
语法: |
Math.floor(x) |
注意:返回的是小于或等于x,并且与 x 最接近的整数。 |
我们将在不同的数字上使用 floor() 方法,代码如下: |
<script type= "text/javascript" > |
document.write(Math.floor(0.8)+ "<br>" ) |
document.write(Math.floor(6.3)+ "<br>" ) |
document.write(Math.floor(5)+ "<br>" ) |
document.write(Math.floor(3.5)+ "<br>" ) |
document.write(Math.floor(-5.1)+ "<br>" ) |
document.write(Math.floor(-5.9)) |
</script> |
运行结果: |
0 |
6 |
5 |
3 |
-6 |
-6 |