JavaScript中Math--random()/floor()/round()/ceil()

Math.random():返回0-1之间的任意数,不包括0和1;

Math.floor(num):返回小于等于num的整数,相当于四舍五入的四舍,不五入;例子:Math.floor(1.0);Math.floor(1.5);Math.floor(1.9);都返回1;

Math.round(num):num进行四舍五入;例子:Math.round(1.0);Math.round(1.4);返回1;/Math.round(1.5);Math.round(1.9);返回2;

Math.ceil(num):返回大于等于num的最小整数;Math.ceil(1.0);返回1;/Math.ceil(1.1);Math.ceil(1.5);Math.ceil(1.9);返回2;

原文地址:https://www.cnblogs.com/jinxiao/p/4199348.html