Math对象

2018-08-14  本文已影响0人  空压机百科

实例对象:通过构造函数创建出来,实例化的对象

静态对象:不需要创建直接就是一个对象,方法(静态方法)直接通过对象名字调用

实例方法必须通过实例对象调用
静态方法必须通过大写的对象调用

Math.PI -----π-----

console.log(Math.PI );

Math.E -----常数的底数

console.log(Math.E);

Math.abs(值) -----绝对值

console.log(Math.abs(1));
console.log(Math.abs(-55));
console.log(Math.abs('string'));

Math.ceil(值) -----向上取整

console.log(Math.ceil(12.01));
console.log(Math.ceil(12.91));

Math.floor(值) -----向下取整

console.log(Math.floor(12.01));
console.log(Math.floor(12.91));
console.log(Math.floor(-12.15));

Math.max(数组) -----最大值

console.log(Math.max(5,0,7,9,55,14,62,78));

Math.min(数组) -----最小值

console.log(Math.min(5,0,7,9,55,14,62,78));

Math.pow(x,y) -----x的y次幂

console.log(Math.pow(2,10));

Math.sqrt(x) -----x的平方根

console.log(Math.sqrt(16));

Math.random() -----返回一个浮点,范围大于等于0小于1

console.log(Math.random());

Math.round:四舍五入

console.log(Math.round());

获取m-n之间的随机整数

Math.round(Math.random()*(m-n)+n)
上一篇 下一篇

猜你喜欢

热点阅读