mysql> SELECT ROUND(-6.6),ROUND(-8.44),ROUND(3.44); +-------------+--------------+-------------+ | ROUND(-6.6) | ROUND(-8.44) | ROUND(3.44) | +-------------+--------------+-------------+ | -7 | -8 | 3 | +-------------+--------------+-------------+ 1 row in set (0.00 sec)从执行结果可以看出,ROUND(x)函数将值x四舍五入之后保留了整数部分。
mysql> SELECT ROUND(-6.66,1),ROUND(3.33,3),ROUND(88.66,-1),ROUND(88.46,-2); +----------------+---------------+-----------------+-----------------+ | ROUND(-6.66,1) | ROUND(3.33,3) | ROUND(88.66,-1) | ROUND(88.46,-2) | +----------------+---------------+-----------------+-----------------+ | -6.7 | 3.330 | 90 | 100 | +----------------+---------------+-----------------+-----------------+ 1 row in set (0.00 sec)从执行结果可以看出,根据参数y值,将参数x四舍五入后得到保留小数点后y位的值,x值的小数位不够y位的补零;如果y为负值,则保留小数点左边y位,先进行四舍五入操作,再将相应的位数值取零。
本文链接:http://task.lmcjl.com/news/16786.html