math对象的方法有:1、round(),用于四舍五入;2、ceil(),可向上取整;3、floor(),可向下取整;4、pow(),可返回x的y次幂;5、sqrt(),可返回一个数的平方根;6、max();7、min();8、random();9、abx();10、sin();11、asin();12、cos();13、acos();14、tan();15、exp()。
本教程操作环境:windows7系统、jquery3.6版本、Dell G3电脑。
jquery Math对象方法
四舍五入 Math.round()
Math.round()
Math.round(2.2) //--2
Math.round(2.5) //--3
上取整 Math.ceil()
Math.ceil()
Math.ceil(2.2) //--3
Math.ceil(2.5) //--3
下取整 Math.floor()
Math.floor()
Math.floor(2.2) //--2
Math.floor(2.5) //--2
返回x的y次幂 Math.pow(x,y)
Math.pow(x,y)
Math.pow(2,2) //--4
Math.round(2,3) //--8
返回x的平方根 Math.sqrt()
Math.sqrt(x)
Math.sqrt(4) //2
Math.sqrt(9) //3
Math.sqrt(6) //2.449489742783178
返回 x,y,z,…,n 中的最高值 Math.max(x,y,z,…n)
Math.max(x,y,z,.....n)
//Math.max(2,3,4,6,5)--6
返回 x,y,z,…,n中的最小值 Math.min(x,y,z,…n)
Math.min(x,y,z,.....n)
//Math.max(2,3,4,6,5)--2
返回 0 ~ 1 之间的随机数 Math.random()
Math.random()
//返回0-100之间的随机数 x=100 y=0
返回 x 的绝对值 Math.abx(x)
Math.abx(x)
Math.abx(2) //--2
Math.abx(-2) //--2
返回 x 的正弦值 Math.sin(x)
Math.sin(x)
Math.sin(1)
返回 x 的反正弦值 Math.asin(x)
Math.asin(x)
Math.asin(-2);
Math.asin(-1);
Math.asin(0);
Math.asin(0.5);
Math.asin(1);
Math.asin(2);
返回 x 的余弦 Math.cos(x)
Math.cos(x)
Math.cos(1)
Math.cos(-1)
返回 x 的反余弦值 Math.acos(x)
Math.acos(-1)
Math.acos(-2)
Math.acos(0)
Math.acos(1)
//对于小于 -1 或大于 1 的参数值,Math.acos 返回 NaN。
返回角的正切 Math.tan()
Math.tan()
Math.tan(15)
返回 E的x次方 的指数 Math.exp(x)
//x 表示参数,e 是欧拉常数(Euler's constant),自然对数的底数。
Math.exp(2)
Math.exp(6)
【推荐学习:jQuery视频教程、web前端视频】