Math.ceil、Math.floor 與 Math.round 是三個常見的取整函式。
Math.ceil 會向上取整,也就是取得大於或等於該數的最小整數。
Math.floor 會向下取整,也就是取得小於或等於該數的最大整數。
Math.round 會四捨五入到最接近的整數。
Math.ceil(3.2); // 4 Math.floor(3.8); // 3 Math.round(3.5); // 4
只要記住向上、向下與最接近這三個概念,就不容易混淆。