*向上取整【只要有小數就+1】
Math.ceil(3.14); // 4
*向下取整【有小數就舍棄】
Math.floor(3.14); // 3
parseInt(3.14); // 3
// 常用于字符串類型的數字轉為十進制的數據
四舍五入【小數點后部分】
Math.round(11.5)); //12
Math.round(-11.5)); //-11
取兩數中的最大
Math.max(1,2); // 2
Math.max([1,2,3]) // 3
取兩數中的最小
Math.min(1,2); // 1
Math.min([5,6,8,14]); // 5
隨機數
// 獲取隨機數0-1
Math.random();
//0.1 0.3 0.5 ...
// 生成一個指定區間內的隨機數
function getRandomNumber(min, max) {
// 計算區間范圍
const range = max - min + 1;
// 生成隨機數并進行范圍轉換
const randomNumber = Math.fl