1.min()和max()方法
找出一組數值中的最小和最大值
Math.min(5,4,3,2,1);
Math.max(5,4,3,2,1);
2.舍入方法
Math.ceil()執行向上舍入,即它總是將數值向上舍入為最接近的整數;
Math.floor()執行向下舍入,即它總是將數值向下舍入為最接近的整數;
Math.round()執行標準舍入,即它總是將數值四舍五入為最接近的整數;
Math.ceil(23.6);//24
Math.floor(23.6);//23
Math.round(23.6);//24
3.random()方法
Math.random()方法返回介于0到1之間一個隨機數,不包括0和1。如果想大于這個范圍的話,可以套用一下公式:
值 = Math.floor(Math.random() * 總數 + 第一個值)
Math.floor(Math.random()*10+1);//隨機產生一個1-10的數。
Math.floor(Math.random()*10+5);//隨機產生一個5-14的數。
4.其他方法
image.png