Math及其常用的方法
1.Math数学函数,但是它属于对象类型的
typeof Math => "object"
之所以叫做数学函数,是因为Math这个对象中提供了很多操作数字的方法
2.Math中提供的方法
abs
: 取绝对值
ceil / floor
: 向上/向下取整
round
:四舍五入
max / min
: 取最大值和最小值
sqrt
:开平方
pow
: 取幂(N的M次方)
console.log(2,10); //=>1024
PI
:获取圆周率
random
: 获取0~1之间的随机小数
Math.round(Math.random()*(m-n)+n)
: 获取n~m 之间的随机整数