- ceil:
向上取捨
-floor:
向下取捨
-round:
實際上,Math.round()方法準確說是“四捨六入”,對0.5要進行判斷對待。
Math.round()的原理是對傳入的參數+0.5之後,再向下取整得到的數就是返回的結果。這裏的向下取整是說取比它小的第一個整數或者和它相等的整數。
因此Math.round(-1.5)的結果是-1.5 + 0.5 再向下取整,即-1.0取整,結果是-1.。
Math.round(-1.4)的結果是 -1.4 + 0.5 即-0.9 向下取整,結果是-1。
同理,Math.round(1.5)即爲 1.5 + 0.5 再向下取整,結果是2。