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

猜你喜欢

转载自www.cnblogs.com/taohuaya/p/9556256.html