<script>
alert(Math.round(1.4));//值为1;最接近的整数
alert(Math.round(1.6));//值为2;最接近的整数
alert(Math.floor(1.6));//值为1;
alert(Math.floor(-1.6));//值为-2;
alert(Math.ceil(1.6));//值为2
alert(Math.ceil(1.1));//值为2
alert(Math.random()*10);//获得0~10的随机数
alert(Math.abs(-1));//值为1,获得绝对值
</script>
javascript中的Math
最新推荐文章于 2025-06-17 20:22:13 发布
本文详细介绍了JavaScript中常用的数学函数,包括Math.round()、Math.floor()、Math.ceil()、Math.random()及Math.abs()等函数的功能与用法。通过具体实例展示了如何使用这些函数进行数值处理。
4920

被折叠的 条评论
为什么被折叠?



