jquery中math对象的方法有哪些

前端技术 03/12 jQuery

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中math对象的方法有哪些的详细内容,更多请关注本站点其它相关文章!

本文地址:https://www.stayed.cn/item/26864

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。