Math 对象
Posted taohuaya
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Math 对象相关的知识,希望对你有一定的参考价值。
Math对象提供了,我们一般进行数学运算的所有函数。
Math.random() 随机0~1之间的随机数 [0, 1)
Math.max() 求传入参数的最大数
Math.min() 求传入参数的最小数
Math.abs() 求绝对值
Math.ceil() 向上取整
Math.floor() 向下取整
Math.round() 四舍五入
Math.pow(x, y) x的y次方
Math.sqrt() 开平方
// alert(Math.max(10, 20, 30, 40)); // alert(Math.min(10, 20, 30, 40)); // alert(Math.abs(-10));//10 /*var num = 3.55; alert(Math.round(num));//4*/ // alert(Math.ceil(3.1));4 // alert(Math.floor(3.9));//3 // // alert(Math.sqrt(36));//6 alert(Math.pow(2, 5));//32
以上是关于Math 对象的主要内容,如果未能解决你的问题,请参考以下文章
VSCode自定义代码片段12——JavaScript的Promise对象