50.数学对象Math

1.圆周率 Math.PI

2.随机数,是多位小数,范围【0,1) Math.radom()   

   后面可以加减乘除 来获取想要的范围:

                                 取值【2,10)

                                                        

3.给Math.random()取整:·

         1.parseInt()   2. Math.ceil()   3.Math.floor()

 parseInt(Math.random())

Math.random() 是【0,1)的随机多位小数,parseInt可取整,Math.ceil() 可向上取整  Math.floor() 可向下取整

Math.ceil() 上取整,取到范围内最大整数,可超范围 Math.ceil(Math.random()*10) //  范围值为【1,10】      1.99,上取整就是2

Math.floor() 下取整,取到范围内最小整数 Math.floor(Math.random())// 0                                                          1.99下取整就是1

  ♥:注意 这里 范围是 【1,10】     先ceil [0,1]  ,1, 再 *10 故范围是【1,10】 

                                                                                                       如果是floor ,范围就是【0,9】

Math.ceil Math.floor 里面会有隐式转换过程

会忽略aa

4.Math.max(),里面不可传非数字的字符串。只要有结果就是NaN 这与Math.ceil Math.floor不同

   Math.min()取最小值

5.Math.abs(a,b)取绝对值最小值


6.三角函数

Math.sin  Math.cos Math.tan

注意:js 不同于css,js 不能识别deg ,因此参数必须是弧度值,最大弧度2*Math.PI

7.Math.pow(x,y)  x 的 y 次幂,只接受两个参数,过多的参数会被忽略

幂为负数 比如 Math.pow(-2,-3) 算法为 1/(-2)*(-2) *(-2)

8.Math.sqrt() 开方

//3

原文地址:https://www.cnblogs.com/yzdwd/p/12631649.html