上舍入 Math.ceil()
Math.ceil(1.2345)
2
Math.ceil(1.2345*100) / 100
1.24
下舍入 Math.floor
Math.floor(1.2345)
1
Math.floor(1.2345*100) / 100
1.23
四舍五入 Math.round
Math.round(1.2345)
1
Math.round(1.5345)
2
只保留整数部分(丢弃小数部分) parseInt
parseInt(1.2345)
1
parseInt(1.7345)
1
取绝对值 Math.abs
Math.abs(-1)
1
返回两数中的较大者 Math.max
Math.max(1,2)
2
返回两数中的较小者 Math.min
Math.min(1,2)
1
随机数(0-1)返回 0(包括) 至 1(不包括) 之间的随机数 Math.random
Math.random()
0.05559749299436745
随机数(0-9) Math.floor(Math.random() * 10)
随机数(0-99) Math.floor(Math.random() * 100)
随机数(1-10) Math.floor(Math.random() * 10) + 1
随机数(1-100) Math.floor(Math.random() * 100) + 1