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