首页 > 其他 > 详细

Math 对象

时间:2018-08-29 19:04:00      阅读:184      评论:0      收藏:0      [点我收藏+]

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 对象

原文:https://www.cnblogs.com/taohuaya/p/9556256.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!