十一天

导航

JavaScript Math属性和方法

Math:提供大量数学运算的属性和方法

属性:

console.log(Math.E);           //2.71828
console.log(Math.PI);          //3.14159

 

方法:

console.log(Math.min(12,65,-78));              //取最小值12
console.log(Math.max(12,65,-78));              //取最大值-78

 

console.log(Math.round(12.987));              //四舍五入取整13
Math.round(数字*100)/100; //保留2位小数
console.log(Math.ceil(-12.987)); //向上取整-12 console.log(Math.floor(-12.987)); //向下取整-13

 

Math.random();                 //[0,1)随机取小数
Math.random(2);                //参数为随机种子

[30,88]随机数
Math.round(Math.random()*58)+30;

 

Math.sin(30*Math.PI/180);          //30度转化为弧度,*Π/180

 一般段位会这些够了。

posted on 2020-08-21 16:48  十一天  阅读(103)  评论(0编辑  收藏  举报