Math对象小笔记

时间:2025-05-11 09:33:27

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

1.E  自然对数的底数

Math.E; //2.718281828459045

2.PI 圆周率

Math.PI; //3.141592653589793

3.ceil 对数进行上舍入。

Math.ceil(2.1); //

4.floor 向下进行舍入

Math.floor(2.9); //

5.round 四舍五入

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

6.max 最大数

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

7.min 最小数

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

8.pow sqrt 平方 开方

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

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); //