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,则该函数将X返回四舍五入到D的小数位。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)
从上面的定义和示例中,我们可以观察到这三个函数之间的以下区别:
ROUND()函数根据第二个参数D和数字本身对数字进行向上或向下取整(D小数点后的位数是否大于等于5)。
FLOOR()函数将数字四舍五入为零,总是向下。
CEILING()函数将数字四舍五入,始终远离零。
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)