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