Skip to the content.

Math方法

标签(空格分隔): 未分类


Math.floor():向下取整

Math.floor(2.8) – 2 Math.floor(2.2) – 2

Math.ceil():向上取整

Math.ceil(2.8) – 3 Math.ceil(2.2) – 3

Math.round():四舍五入

Math.round(2.8) – 3 Math.round(2.2) – 2

Math.random() : 0-1之间的随机数 0<=X<1

X-Y之间的随机数:

Math.round(random()*(Y-X) + X)