首页  >  文章  >  web前端  >  jquery中math对象的方法有哪些

jquery中math对象的方法有哪些

青灯夜游
青灯夜游原创
2023-01-18 13:58:412077浏览

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()。

jquery中math对象的方法有哪些

本教程操作环境: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)
//返回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)
//返回 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)
//返回 x,y,z,...,n中的最小值 
//Math.max(2,3,4,6,5)--2

返回 0 ~ 1 之间的随机数 Math.random()

Math.random()
//返回 0 ~ 1 之间的随机数
//返回0-100之间的随机数  x=100 y=0
//parseInt(Math.random()*(x - y + 1) + y)

返回 x 的绝对值 Math.abx(x)

Math.abx(x)
//返回 x 的绝对值
Math.abx(2) //--2
Math.abx(-2) //--2

返回 x 的正弦值 Math.sin(x)

Math.sin(x)
//返回 x 的正弦值
Math.sin(1)
//0.8414709848078965

返回 x 的反正弦值 Math.asin(x)

Math.asin(x)
//返回 x 的反正弦值
Math.asin(-2);  // NaN
Math.asin(-1);  // -1.5707963267948966 (-pi/2)
Math.asin(0);   // 0
Math.asin(0.5); // 0.5235987755982989
Math.asin(1);   // 1.570796326794897 (pi/2)
Math.asin(2);   // NaN
//对于小于 -1 或大于 1 的参数值,Math.asin 返回 NaN。

返回 x 的余弦 Math.cos(x)

Math.cos(x)
Math.cos(1)
//0.5403023058681398
Math.cos(-1)
//0.5403023058681398

返回 x 的反余弦值 Math.acos(x)

Math.acos(-1)
//3.141592653589793
Math.acos(-2)
//NaN
Math.acos(0)
//1.5707963267948966
Math.acos(1)
//0
//对于小于 -1 或大于 1 的参数值,Math.acos 返回 NaN。

返回角的正切 Math.tan()

Math.tan()
Math.tan(15)
//-0.8559934009085188

返回 E的x次方 的指数 Math.exp(x)

//x 表示参数,e 是欧拉常数(Euler's constant),自然对数的底数。
Math.exp(2)
//7.38905609893065
Math.exp(6)
//403.4287934927351

【推荐学习:jQuery视频教程web前端视频

以上是jquery中math对象的方法有哪些的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn