方法一:向上取整Math.ceil();
舉例:Math.ceil(11.4)=12; Math.ceil(-11.6)=-11;算法
方法二:向下取整Math.floor();
舉例:Math.floor(11.7)=11;Math.floor(-11.2)=-12;ide
方法三:四捨五入Math.round();
顧名思義,四捨五入後取整,其算法爲Math.round(x+0.5),即原來的數字加上0.5後再想下取整便可。
舉例:Math.round(11.5)=12;
Math.round(-11.5)=-11;it