JavaScript Math对象

来源:互联网 发布:手机数据流量改dns 编辑:程序博客网 时间:2024/06/05 15:08

1.向上取整(.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>

2.向下取整(.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>

3.四舍五入(.round()):

<span style="font-size:18px;"><script type="text/javascript">  document.write(Math.round(1.6)+ "<br>");  document.write(Math.round(2.5)+ "<br>");  document.write(Math.round(0.49)+ "<br>");  document.write(Math.round(-6.4)+ "<br>");  document.write(Math.round(-6.6));</script></span>

4.随机数(.random()):

<script type="text/javascript">  document.write(Math.random());//0-1之间</script>


0 0
原创粉丝点击