Math对象

用于数学运算

不需要创建对象,可以直接使用其中的API

 PI  圆周率

console.log(Math.PI);==>3.141592653589793

 abs  获取绝对值

console.log(Math.abs(-1));===>1

 ceil  向上取整

console.log(Math.ceil(4.99));===>5

console.log(Math.ceil(3.05));===>4

 floor  向下取整

console.log(Math.floor(4.99));==>4

console.log(Math.floor(3.45));==>3

 round   四舍五入取整   

console.log(Math.round(4.99));==>5

console.log(Math.round(4.45));==>4

 max  取一组数字最大值

console.log(Math.max(4,2,1,3,6));==>6

 min  取一组数字最小值

console.log(Math.min(4,2,1,3,6));==>1

 pow  取x的y次方

console.log(Math.pow(5,2));==>25  5的平方

 random   取随机数,范围0~1   >=0  <1

console.log(Math.random());==>0.28856575735647283

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容