Math对象小笔记

 来,总结下Math对象的常用方法和属性

1.E  自然对数的底数

Math.E; //2.718281828459045

2.PI 圆周率

Math.PI; //3.141592653589793

3.ceil 对数进行上舍入。

Math.ceil(2.1); //3

4.floor 向下进行舍入

Math.floor(2.9); //2

5.round 四舍五入

Math.round(2.4); //2
Math.round(2.5); //3

6.max 最大数

Math.max(1,5,9,51,6,22);  //51

7.min 最小数

Math.min(12,5,9,51,6,22); //5

8.pow sqrt 平方 开方

Math.pow(2,3); //8
Math.sqrt(16); //4

9.三角函数

//x是弧度值
Math.sin(x);
Math.cos(x);
Math.tan(x);
//反三角函数
Math.asin(y);
Math.acos(y);
Math.atan(y);
//特殊的还有一个atan2,y是垂直方向的高度,x是水平方向的长度,等价于atan(y/x)
Math.atan2(y,x);

10.abs绝对值

Math.abs(-5); //5

 

posted @ 2017-11-20 14:19  张啊咩  阅读(217)  评论(0编辑  收藏  举报