js算数方法

原文:http://www.w3school.com.cn/js/js_obj_math.asp 

除了可被 Math 对象访问的算数值以外,还有几个函数(方法)可以使用。

函数(方法)实例:

下面的例子使用了 Math 对象的 round 方法对一个数进行四舍五入。

document.write(Math.round(4.7))

上面的代码输出为:5

下面的例子使用了 Math 对象的 random() 方法来返回一个介于 0 和 1 之间的随机数:

document.write(Math.random())

上面的代码输出为:0.9370844220218102

下面的例子使用了 Math 对象的 floor() 方法和 random() 来返回一个介于 0 和 10 之间的随机数:

document.write(Math.floor(Math.random()*11)) 

上面的代码输出为:3

请把你的疑问评论在下方。
原文地址:https://www.cnblogs.com/zzcit/p/5606248.html