CEILING() 函數傳回不小於 X 的最小整數值。請考慮以下範例 –
mysql> Select CEILING(3.46); +---------------+ | CEILING(3.46) | +---------------+ | 4 | +---------------+ 1 row in set (0.00 sec) mysql> Select CEILING(-6.43); +----------------+ | CEILING(-6.43) | +----------------+ | -6 | +----------------+ 1 row in set (0.02 sec)
FLOOR() 函數傳回不大於 X 的最大整數值。請考慮以下範例 –
mysql> Select FLOOR(-6.43); +--------------+ | FLOOR(-6.43) | +--------------+ | -7 | +--------------+ 1 row in set (0.00 sec) mysql> Select FLOOR(3.46); +-------------+ | FLOOR(3.46) | +-------------+ | 3 | +-------------+ 1 row in set (0.00 sec)
ROUND() 函數傳回 X 四捨五入到最接近的整數。如果提供了第二個參數 D,則函數傳回四捨五入到 D 位小數的 X。 D 必須為正數,否則小數點右邊的所有數字將會被刪除。考慮以下範例-
mysql>SELECT ROUND(5.693893); +---------------------------------------------------------+ | ROUND(5.693893) | +---------------------------------------------------------+ | 6 | +---------------------------------------------------------+ 1 row in set (0.00 sec) mysql>SELECT ROUND(5.693893,2); +---------------------------------------------------------+ | ROUND(5.693893,2) | +---------------------------------------------------------+ | 5.69 | +---------------------------------------------------------+ 1 row in set (0.00 sec)
從上面的定義和範例中,我們可以觀察到這三個函數之間的以下差異-
mysql> Select ROUND(1.415,2),FLOOR(1.415),CEILING(1.415); +----------------+--------------+----------------+ | ROUND(1.415,2) | FLOOR(1.415) | CEILING(1.415) | +----------------+--------------+----------------+ | 1.42 | 1 | 2 | +----------------+--------------+----------------+ 1 row in set (0.00 sec)
以上是在 MySQL 中,CEILING() 和 FLOOR() 函數與 ROUND() 函數有何不同?的詳細內容。更多資訊請關注PHP中文網其他相關文章!