欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
算数方法
除了可被 Math 对象访问的算数值以外,还有几个函数(方法)可以使用。
 
下面的例子使用了 Math 对象的 round 方法对一个数进行四舍五入。
 
document.write(Math.round(4.7));
上面的代码输出为:
 
5
下面的例子使用了 Math 对象的 random() 方法来返回一个介于 0 和 1 之间的随机数:
 
document.write(Math.random());
上面的代码输出为:
 
0.5861595901024819
下面的例子使用了 Math 对象的 floor() 方法和 random() 来返回一个介于 0 和 11 之间的随机数:
 
document.write(Math.floor(Math.random()11));
上面的代码输出为:
 
8

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h65058.shtml