Math / 随机数生成
Math / 随机数生成
/**
* Math
*
* Math.PI 表示 圆周率
*/
// console.log(Math);
// console.log(Math.PI);
// Math.ceil() 向上取整
// console.log(Math.ceil(1.1));//2
// Math.floor() 向下取整
// console.log(Math.floor(1.9));// 1
// Math.round() 四舍五入
// console.log(Math.round(1.9));// 2
// console.log(Math.round(1.5));// 2
// console.log(Math.round(1.4));// 1
/**
* Math.random()
* 可以生成一个 0-1 之间的随机数
* 生成一个 0-10 之间的随机数
* Math.round(Math.random() * 10)
* 生成一个 0-x 之间的随机数
* Math.round(Math.random() * x)
*
* 生成一个 1-10 之间的随机数
* Math.round(Math.random() * 9) + 1
*
* 生成一个 x-y 之间的随机数
* Math.round(Math.random() * (y-x)) + x
*/
// console.log(Math.random());
// 生成一个 1-6 之间的随机数
// console.log(Math.round(Math.random() * 5 + 1));
// // max() 获取多个 数中的最大值
// var max = Math.max(10,45,30)
// console.log(max);
// // min() 获取多个 数中的最小值
// var min = Math.min(10,45,30)
// console.log(min);
// Math.pow(x,y) 返回 X 的 y 次幂
console.log(Math.pow(2,3)); // 2 * 2 * 2
// Math.sqrt(9) 开方
console.log(Math.sqrt(9)); // 3
我是Eric,手机号是13522679763
来源https://www.cnblogs.com/eric-share/p/14729435.html