js种Math对象里的方法具体怎么用

2024-10-16 21:20:28

1、console.log("math.e=",Math.E);//e=2.718。。 console.log("math.pi",Math.PI);//Π=3.14.。。。console.log("math.sqrt=",Math.sqrt(4));console.log("math.sqrt=",Math.sqrt(16));console.log("math.sqrt=",Math.sqrt(25));最后sqrt是开平方

js种Math对象里的方法具体怎么用

2、console.log("\n");//正数or负数or0,5种返回类型console.log("math.sign=",Math.sign(3));//1console.log("math.sign=",Math.sign(-6));//-1console.log("math.sign=",Math.sign(0));//0console.log("math.sign=",Math.sign(-0));//-0console.log("math.sign=",Math.sign('sfa'));//NaN判断正数还是负数以及0或其他。正数返回1,负数为-1,正0为0,负0为-0,其他类型为NaN

js种Math对象里的方法具体怎么用

3、//指数类console.log("math.exp=",Math.exp(2));//e的多少次方console.log("math.pow=",Math.pow(1,4));//a的b次方 console.log("math.pow=",Math.pow(2,4));console.log("math.expm1=",Math.expm1(1));//Ex-1,e的x次方减一

js种Math对象里的方法具体怎么用

4、//取大取小console.log('math.floor=',Math.floor(4.657));console.log('math.ceil=',Math.ceil(4.657));console.log('math.round=',Math.round(4.657));floor:地板,向下取整ceil:天花板:向上取整round:周围:四舍五入

js种Math对象里的方法具体怎么用

5、//取lnconsole.log("math.ln2=",Math.LN2);//log以e为底2的对数console.log("math.ln10=",Math.LN10);//log以e为底10的对数console.log("math.log2e=",Math.LOG2E);//log2econsole.log("math.log2e=",Math.LOG10E);//log10econsole.log("math.max=",Math.max(1,5,6,-9));console.log("math.min=",Math.min(1,5,6,-9));console.log("math.abs=",Math.abs(-10));最后三个分别取最大值、最小值、绝对值

js种Math对象里的方法具体怎么用

6、console.log("math.sin=",Math.sin(Math.PI/6));leta=Math.PI/6,b=Math.PI/3letc=Math.PI/2console.log("sin30=",a);console.log("cos60=",b);console.log("cos90=",c);console.log("math.sin30+cos60=",Math.sin(a)+Math.cos(b));注意:sin和cos函数里面写弧度

js种Math对象里的方法具体怎么用
猜你喜欢