jquery中关于Math对象的各种用法

582 ℃

jquery中关于Math对象有哪些用法,下面web建站小编给大家详细介绍一下各种方法!

Math.round()

//四舍五入
Math.round(2.2) //--2
Math.round(2.5) //--3

Math.ceil()

//上取整
Math.ceil(2.2) //--3
Math.ceil(2.5) //--3

Math.floor()

//下取整
Math.floor(2.2) //--2
Math.floor(2.5) //--2

Math.pow(x,y)

//返回x的y次幂
Math.pow(2,2) //--4
Math.round(2,3) //--8

Math.sqrt()

//返回x的平方根
Math.sqrt(4) //2
Math.sqrt(9) //3
Math.sqrt(6) //2.449489742783178

Math.max(x,y,z,…n)

//返回 x,y,z,...,n 中的最高值
//Math.max(2,3,4,6,5)--6

Math.min(x,y,z,…n)

//返回 x,y,z,...,n中的最小值 
//Math.max(2,3,4,6,5)--2

Math.random()

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

Math.abx(x)

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

Math.sin(x)

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

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。

Math.cos(x)

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

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(15)
//-0.8559934009085188

Math.exp(x)

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

js如何随机生成颜色并赋值css样式

js如何封装一个获取随机数方法(指定范围)

js实现四舍五入并保留小数点

数学题:js如何实现次方计算(附代码)

js如何创建随机整数(随机数)

标签: Math.abx, Math.acos, Math.asin, Math.ceil, Math.cos, Math.exp, Math.floor, Math.max, Math.min, Math.pow, Math.random, Math.round, Math.sin, Math.tan

上面是“jquery中关于Math对象的各种用法”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_3257.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

C语言中常用运算符的优先级顺介绍
java8中如何对代码做注解
js如何实现数组内求和
帝国cms技巧之如何在首页加上“最后更新时间”
wordpress主题文章页面single.php标签介绍