首先,这三个函数都是取整。
Math.round可以简单地理解为“四舍六入”,例如:
Math.round(10.45)=10
Math.round(10.65)=11
Math.round(-10.45)=10
Math.round(-10.65)=11
但是当赋值数小数点后第一位为5时,即x.5时,正数整数位+1,负数整数位不+1,例如:
Math.round(-10.5)=10
Math.round(10.5)=11
Math.ceil是赋值数是正数时,则整数位+1,是负数则整数位不+1,例如:
Math.ceil(10.45)=Math.ceil(10.5)=Math.(10.65)=11
Math.ceil(-10.45)=Math.ceil(-10.5)=Math.(-10.65)=-10
Math.floor与Math.ceil相反,赋值数是正数,则整数位不+1,是负数则整数位+1,例如:
Math.floor(10.45)=Math.floor(10.5)=Math.floor(10.65)=10
Math.floor(-10.45)=Math.floor(-10.5)=Math.floor(-10.65)=-11