js知识点 Ⅷ
数字对象
- 数字对象Math 与Number 是不同的对象
- console.log(Math);
- console.log(Number);
- 常用的数字对象
- Π————var pai = Math.PI;
- 随机数 0~1 包含0不包括————var random = Math.random();
- 向上取整————var num = Math.ceil(1.3);
- 向下取整————var num1 = Math.floor(1.7);
- 四舍五入————var num2 = Math.round(1.3);
- 绝对数————var add = Math.abs(-1);
- 最大值————var max = Math.max(1,2,3,4);
- 最小值————var min = Math.min(-1,-2,-3,-4)
- x 的 y 次幂————var pow = Math.pow()
- 求10~99 的随机整数————Math.floor(Math.random)*(max-min+1)+min)
- 其他的数字对象
- Math.E: 自然对数的底数(e)
- Math.LN10: loge10
- Math.LN2: loge2
- Math.LOG10E: log10e
- Math.LOG2E: log2e
- Math.PI: 3.1415926
- Math.SQRT1_2: 2的平方根的倒数
- Math.SQRT2: 2的平方根
- Math.sqrt(): 平方根