目录
一、Math对象下的方法
1、取绝对值:
Math.abs(-9)
2、返回x的y次幂:
Math.pow(2,10)
3、返回某个数的算数平方根:
Math.sqrt(9)
4、返回几个数中的最大值:
Math.max(10,20,5,15)
5、返回几个数中的最小值:
Math.min(10,20,5,15)
6、四舍五入,得到整数:
Math.round(88.88)
7、向上取整:
Math.ceil(9.34)
8、向下取整:
Math.floor(9.99)
9、取整:
parseInt(2.76)
10、取0-1之间的随机数(包括0,不包括1):
Math.random()
二、取两个数之间的随机整数
1、round方法(四舍五入):var n=Math.round(Math.random()*(max-min)+min)
2、floor方法(向下取整):var n=Math.floor(Math.random()*(max-min+1)+min)
12-28
1264