Math对象 里面提供的方法,可以帮助我们解决算术问题
提供的方法:
(1) Math.random()
作用:返回一个0到1之间的随机数
语法; console.log(parseInt(Math.random()*1001)+1000);
(2)abs()
作用:返回一个数的绝对值
语法:console.log(Math.abs(-55));
(3)ceil()
作用:向上取整(只要有小数,就进一)
语法:console.log(Math.ceil(55.01));
(4)floor()
作用:向下取整(去掉所有小数点)
语法:console.log(Math.floor(55.99));
(5)max()
作用:返回最大值
语法: console.log(Math.max(11,22,33,38,2,3,4));
(6)min()
作用: 返回最小值
语法: console.log(Math.min(11,22,33,38,2,3,4));
(7)pow()
作用:返回指定数的次幂
语法:console.log(Math.pow(3,3));
console.log(Math.pow(4,4));
(8)round()
作用:四舍五入
语法: console.log(Math.round(55.5));
console.log(Math.round(55.4));
console.log(Math.round(-55.5));
console.log(Math.round(-55.6));
(9)sqrt()
作用:开平方根
语法: console.log(Math.sqrt(16))