Math 数学的方法

Math

    // console.log(Math);// 对象;

    
1. Math.max : 获取一组数的最大值
     //console.log(Math.max(12, 3, 45, 109, 4));//109

    
2.Math.min
     //console.log(Math.min(12, 3, 0, 109, 4));//0

    
3. Math.floor : 向下取整
     //console.log(Math.floor(4.999));//4
     //console.log(Math.floor(-4.999));//-5

    
4.Math.ceil() : 向上取整
     //console.log(Math.ceil(4.01));// 5
     //console.log(Math.ceil(-4.01));// -4

   
5.Math.round() : 四舍五入;保留整数;
     console.log(Math.round(4.499));//4

   
6.Math.random();产生一个[0,1)的随机小数;
     //console.log(Math.random());
     Math
.random()产生一个m--n之间的随机整数;
     //Math.round(Math.random()*(n-m)+m);
     //Math.round(Math.random()*(90-40)+40)

   
7.Math.pow() :取数字的幂次方Math.pow(n,m) n的m次方
    //console.log(Math.pow(2, 6));64

   
8.Math.sqrt() :开平方
    //console.log(Math.sqrt(64));//8

   
9.Math.abs() :对负数取绝对值;
    //console.log(Math.abs(-12));//12

   
10.Infinity 无穷大  -Infinity无穷小

猜你喜欢

转载自www.cnblogs.com/MrZhujl/p/9937605.html