1 Math工具类方法: =>和其他的类的不同,Math并不是一个构造函数,也就是无法通过new来创建Math的实例 =>Math表示的数学,在Math对象中存储了一组数学运算相关的常量的和方法 =>这些常量和方法可以直接通过Math来访问 =>比如Math.PI用来表示圆周率 =>像Math这种对象,我们称其为工具类 // console.log(Math.PI);
/*
Math.PI 表示圆周率
Math.abs(x) 返回一个数的绝对值
Math.ceil(x) 向上取整(尽量往大了取)
Math.floor(x) 向下取整(尽量往小了取)
Math.round(x) 四舍五入取整
*/
var a = -10;
var result = Math.abs(a);
result = Math.ceil(3.5); // 4
result = Math.ceil(3.1); // 4
result = Math.ceil(3.01); // 4
result = Math.floor(3.5); //3
result = Math.floor(3.99); //3
result = Math.ceil(-3.01); //-3
result = Math.floor(-3.99); //-4
result = Math.round(3.5);//4
result = Math.round(3.44444444);//3
// result = Math.round(-3.44444444);//-3
// result = Math.round(-3.5555);//-4
// console.log(result);
// parseInt()虽然也可以进行取整,但是不要用它取整,它的性能很差
// var num = ……