js中的Math对象
常用的方法有:
-
Math.abs(); --- 返回绝对值(正数的绝对值是它本身, 负数的绝对值是它的相反数)
-
Math.ceil() --- 对数进行上舍入
-
Math.floor() --- 对数进行下舍入
-
Math.round() --- 对数进行四舍五入
-
Math.random() --- 返回一个0~1之间的随机数(0,1]
console.log(Math.random()); // 0.24953691032055114
// 获取 1~10 之间的随机整数
console.log(Math.floor(1 + Math.random() * 10)); // 3
转载必须注明出处:https://www.zhiqiexing.com/145.html