Math的方法使用
1、Math.random():方法可返回介于 0(包含) ~ 1(不包含) 之间的一个随机数。
Math.random()//0.254542157154
2、Math.floor():方法返回小于等于x的最大整数(向下取整)。如果传递的参数是一个整数,该值不变。
Math.floor(2.4)//2
3、Math.ceil():方法可对一个数进行上舍入(向上取整)。如果参数是一个整数,该值不变。
Math.ceil(5.6)//6
4、Math. abs():方法可返回一个数的绝对值。
Math.abs(-8)//8
Math.abs(8)//8
5、Math.round():方法可把一个数字舍入为最接近的整数。
Math.round(2.5)//3
Math.round(5.2)//5
6、Math.pow():方法返回 x 的 y 次幂。
Math.pow(3,2)//9
7、Math.sqrt():方法可返回一个数的平方根。
Math.sqrt(9)//3
8、Math. cbrt():方法可返回一个数的立方根。
Math.cbrt(8)//2
9、Math.sin():函数返回一个数值的正弦值。
Math.sin(45*Math.PI/180)//0.7071067811865475
Math.sin(90*Math.PI/180)//1
10、Math.cos():函数返回一个数值的余弦值。
Math.cos(45*Math.PI/180)//0.7071067811865476
Math.cos(0*Math.PI/180)//1
11、Math.tan():函数返回一个数值的正切值。
Math.tan(45*Math.PI/180)//0.9999999999999999
Math.tan(0*Math.PI/180)//0
12、Math.max(): 方法可返回两个或多个指定的数中带有较大的值的那个数。
Math.max(1,4,5,18)//18
13、Math.min():方法可返回指定的数字中带有最小值的数字。
Math.min(1,2,3,4,5)//1
Life is short. Go where you feel love。