Math对象的常用方法
- Math.sign()
取符号,负数返回-1,正数返回1。0返回0,-0返回-0。
js> Math.sign(-7);
-1
js> Math.sign(7);
1
js> Math.sign(0);
0
js> Math.sign(-0);
-0
js> Math.abs(-7);
7
js> Math.abs(7);
7
js> Math.abs(0);
0
js> Math.abs(-0);
0
js> Math.ceil(0.1);
1
js> Math.ceil(1.1);
2
js> Math.ceil(0);
0
js> Math.ceil(-0);
-0
js> Math.floor(-1.1);
-2
js> Math.floor(-0.1);
-1
js> Math.floor(-0);
-0
js> Math.floor(0);
0
js> Math.round(1.4);
1
js> Math.round(1.5);
2
js> Math.round(1);
1
js> Math.round(0);
0
js> Math.round(-0);
-0
js> Math.max([2,3,4]);
NaN
js> Math.max(2,3,4);
4
js> Math.max("123","23","");
123
js> Math.max("");
0
js> Math.min(2,3,4);
2
js> Math.min("123","23","");
0
- Math.random()
取[0,1)之间的随机数
js> Math.random();
0.08277169470126733
- Math.pow()
求幂,第一个参数为底数,第二个为指数
js> Math.pow(2,2);
4
js> Math.pow(2,3);
8
js> Math.sqrt(4);
2
js> Math.sqrt(9);
3