public final class Math extends Object public static double floor(double a) public static long round(double a) public static int round(float a) public static double ceil(double a) floor 返回不大于的最大整数;ceil 则是不小于他的最小整数;round 它表示"四舍五入"
Math.random():获取0~1随机数 Math.floor() method rounds a number DOWNWARDS to the nearest integer, and returns the result. (小于等于 x,且与 x 最接近的整数.)其实返回值就是该数的整数位:Math.floor(0.666) --> 0Math.floor(39.2783) --> 39 所以我们可以使用Math.floor(Math.random())去获取你想要的一
var arg1 = 12.2; var arg2 = 12.5; var arg3 = 12.7; ceil():将小数部分一律向整数部分进位 var c1 = Math.ceil(arg1); var c2 = Math.ceil(arg2); var c3 = Math.ceil(arg3); console.log(c1,c2,c3) // 13 13 13 floor():一律舍去,仅保留整数. var f1 = Math.floor(arg1); var f2 = Math.floo