开发工具与关键技术:visual Studio jquery
作者:邓伟征
撰写时间:
Math(算数)对象的作用是:执行普通的算数任务。
Math对象提供多种算数数值类型和函数。无需在使用这个对象之前对它进行定义。
round方法:对一个数进行四舍五入
document.write(Math.round(9.9) + “
”);
random()方法:返回一个介于0到1自己的随机数
document.write(Math. random + “
”);
Floor方法:去除余数取整数
document.write(Math.floor(8.8) + “
”);
使用了 Math 对象的 floor() 方法和 random() 来返回一个介于 0 和 100之间的随机数
document.write(Math.floor(Math.random() * 111))
Max()方法:获取数组中最大的数
document.write(Math.max(13, 12,11) + “
”)
document.write(Math.max(14, 4,6) + “
”)
document.write(Math.max(-3, 5,-1) + “
”)
document.write(Math.max(20, 7.30))
Min()方法:获取数组中最小的数
document.write(Math.min(5,99,88) + “
”)
document.write(Math.min(20,30,49) + “
”)
document.write(Math.min(13, 40,55) + “
”)
document.write(Math.min(14, 33.30))
cos方法:返回数的余弦值
document.write(Math.cos(45) + “
”)
sin(x)方法: 返回数的正弦的值
document.write(Math.sin(45) + “
”)、
tan(x)方法: 返回角的正切
document.write(Math.tan(45) + “
”)
exp()方法:返回 e 的指数
document.write(Math.exp(45) + “
”)
sqrt()方法:返回数的平方根
document.write(Math.sqrt(45) + “
”)
ads()方法:返回数的绝对值
document.write(Math.abs(45) + “
”)
atan()方法:以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值。
document.write(Math.atan(45) + “
”)
ayan2()方法:返回从 x 轴到点 (x,y) 的角度(介于 -PI/2 与 PI/2 弧度之间)。
document.write(Math.ayan2(45) + “
”)
ceil()方法:对数进行上舍入
document.write(Math.ceil(45) + “
”)
log()方法:返回数的自然数(底为e)
document.write(Math.log(45) + “
”)
pow()方法:返回x的y次幂
document.write(Math.pow(45) + “
”)
除了方法JavaScript还提供了8种可被Math对象访问的算数值:
Math.E:常数 Math.PI:圆周率 Math.SQRT2:2的平方根
Math.SQRT1_2:1/2的平方根 Math.LN2:2 的自然对数 Math.LN10:10 的自然对数
Math.LOG2E:以 2 为底的 e 的对数 Math.LOG10E:以 10 为底的 e 的对数