Math

1、PI     π(圆周率)的值

2、sqrt ( x )       返回数字的平方根

     例:console.log(Math.sqrt(4));//==>2

3、abs ( x )       返回数字的绝对值 

    例:console.log(Math.abs(-3));//==>3

4、ceil ( x )         返回 x区间的最大整数 

     例:console.log ( Math.ceil ( 3.11 ) );//==>4

5、floor ( x )           返回 x 区间的整数

     例:console.log ( Math.floor (3.99 ) );//==>3

6、max ( x , y )             返回 x 和 y 之间较大的数 

     例:console.log ( Math.max ( 3 , 6 ) );//==>6 

7、min ( x , y )         返回 x 和 y 之间较小的数

     例:console.log ( Math.min ( 3 , 6 ) );//==>3

8、round ( x )           四舍五入后取整 

     例:console.log ( Math.round ( 3.4 ) );//==>3

            console.log ( Math.round ( 3.5 ) );//==>4

9、cos ( x )              返回一个数字的余弦值

     例:

10、sin ( x )             返回数字的正弦值 

     例:

11、tan ( x )             返回一个角度的正切值 

     例:

12、random ( )          返回位于 0 到 1 之间的随机数 

     例:console.log ( Math.random ( );//他返回的数是 0 到 1 之间完全随机的。

          Math.random ( ) *100;//==> 0 到 100 之间随机

          Math.random ( ) *  ( n - m ) + m  //表示从 m 到 n 之间取随机数。

          Math.random ( ) * ( 50 - 25 ) + 25 //从 25 到 50 之间取一个随机数。

你好!如果你有什么更好的建议或意见,请在评论区留言。感谢你的阅读!
原文地址:https://www.cnblogs.com/YCxiaoyang/p/7128689.html