Math
Math的官方函数
1.Math.random()
作用:随机产生0-1之间的数,不包括1
var t = parseInt(Math.random()*10);
随机取出0~10之间的一个整数,不包括10
2.Math.round(n)
作用:四舍五入取整
Math.round(4.2);结果是4
3.Math.ceil(n)
作用:向上取整 (比n大的最小整数)
Math.ceil(4.2)
4.Math.floor(n)
作用:向下取整(舍去小数位)
Math.floor(4.2) 结果为4
5.Math.max
作用:求最大数
Math.max(8,2,1,9,6,20,7) 得结果为20
6.Math.min
作用:求最小数
Math.max(8,2,1,9,6,20,7) 得结果为1
7.Math.pow(底数,指数)
作用:求幂
Math.pow(2,5) :求 2的5次方
8.Math.sqrt(n)
作用:开根号
Math.sqrt(25) 结果为5
9.Math.abs(n)
作用:求绝对值
Math.abs(-8) 结果为8