Oracle SQL-四舍五入 [英] Oracle SQL - Round - Half
本文介绍了Oracle SQL-四舍五入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Oracle ROUND函数默认将向上舍入":
Oracle ROUND function rounds "half up" by default :
select 3.674 my_number,
round(3.674,2) round_on_number
from dual
union
select 3.675 my_number,
round(3.675,2) round_on_number
from dual
union
select 3.676 my_number,
round(3.676,2) round_on_number
from dual
;
MY_NUMBER ROUND_ON_NUMBER
---------- ---------------
3,674 3,67
3,675 3,68
3,676 3,68
我需要四舍五入,这实际上意味着我应该得到以下结果:
I need to round "half down", which essentially means that I should get the following result instead :
MY_NUMBER EXPECTED_ROUND_ON_NUMBER
---------- ------------------------
3,674 3,67
3,675 3,67
3,676 3,68
应该很快,因为我需要对数百万个项目执行此操作.
It should be fast as I need to do this on millions of items.
我可能可以检测到数字是否以"5"结尾,并在这种情况下截断最后一位数字,否则四舍五入,但是我感觉这效率低下(?)
I could probably detect if the number ends with a "5" and trunc that last digit in that case, round otherwise, but I have the feeling this will be inefficient (?)
谢谢! 大卫
推荐答案
查看全文