JS工具对象Math 7个常用 方法

Math工具方法

目前总结 7种

Math.abs(-12);   取绝对值

Math.ceil(-12.99);Math.floor(-12.99);   向上取整  向下取整

Math.round(-12.77);  四舍五入

Math.max(123,44,66,777,412,99,-999); Math.min(21,-1,3,2,1235,213); 获取一组数的 最大值 最小值

Math.random(); 随机数    常用公式   Math.round(Math.random()*(m-n)+n);  //M大于N

1.绝对值函数 Math.abs(-12);

Math.abs(-12); //结果  12

2.返回大于或者等于指定表达式的最小整数 ,向上取整 Math.ceil(-12.99);

Math.ceil(-12.99)//  -12
Math.ceil(12.88)//  13

3.返回小于或者等于指定表达式的最大整数,向下取整Math.floor(-12.99);

Math.floor(-12.99)// -13;
Math.floor(12.99)// 12

4.四舍五入Math.round(-12.77);

Math.round(-12.77)// -13
Math.round(-12.33)// -12

5.取出多个参数中的最大值 Math.max(123,44,66,777,412,99,-999);

Math.max(123,44,66,777,412,99,-999)//  777

6.取出多个参数中的最小值Math.min(21,-1,3,2,1235,213);

Math.min(21,-1,3,2,1235,213)// -1

7.获取(1-10)随机数Math.random();

//获取(n-m)之间的随机整数

Math.round(Math.random()*(m-n)+n);

Math.round(Math.random()*(100-1)+1);// 59

8.可返回一个数的平方根。

Math.sqrt(64);//  8

9.Math.pow() 方法可返回 x 的 y 次幂的值。

Math.pow(8,2)   // 64

10.Math.PI

Math.PI//  3.141592653589793

 

posted @ 2017-04-01 13:20  且听风吟V  阅读(415)  评论(0编辑  收藏  举报