DIV CSS 佈局教程網

Math.ceil、Math.floor、Math.round 三個取整函式重點說明
編輯:JavaScript基礎知識     

Math.ceil、Math.floor 與 Math.round 是三個常見的取整函式。

Math.ceil

Math.ceil 會向上取整,也就是取得大於或等於該數的最小整數。

Math.floor

Math.floor 會向下取整,也就是取得小於或等於該數的最大整數。

Math.round

Math.round 會四捨五入到最接近的整數。

Math.ceil(3.2); // 4
Math.floor(3.8); // 3
Math.round(3.5); // 4

只要記住向上、向下與最接近這三個概念,就不容易混淆。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved