1.Math.ceil()对数进行向上取整 返回大于或等于给定数字的最小整数dom
console.log(Math.ceil(0.95));//1 console.log(Math.ceil(4));//4
2.Math.floor()向下取整ide
console.log(Math.floor(45.95));//45 console.log(Math.floor(-45.05));//-46
3.Math.round()返回一个数字四舍五入后最接近的整数code
console.log(Math.round(45.95));//46 console.log(Math.round(20.5));//21 console.log(Math.round(-20.5));//-20 console.log(Math.round(-20.51));//-21
4.Math.max/min(value1,value2,value3...) 返回给定的一组数字中的最大/最小值 it
console.log(Math.max(1,2,3,78)); //78
5.Math.abs()取绝对值console
console.log(Math.abs(-3));//3
6.Math.pow()得到幂的值class
console.log(Math.pow(2, 3));//8
7.Math.random()随机数随机数
Math.rnd = (max, min = 0) => { return Math.round(Math.random() * (max - min)) + min } console.log(Math.rnd(30, 20));//23