Oracle 四舍五入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19230601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:59:24  来源:igfitidea点击:

Oracle Rounding down

oraclemathrounding

提问by user2855463

Here my partial statement. The statement works and receive the value of 4 but instead I would prefer 3.9 in some cases the number may not be a whole number but .4,.2,.1 etc. Those numbers currently show up as "0" because Oracle rounds up. If I remove "round" I receive 3.9123458543845474586. Is there a way to display 3.9 only and .4,.2 etc. without the rounding? I know its got to be a syntax issue. When I remove round I receive an error.

这是我的部分陈述。该语句有效并接收 4 的值,但在某些情况下,我更喜欢 3.9,该数字可能不是整数,而是 .4,.2,.1 等。这些数字目前显示为“0”,因为 Oracle 向上舍入. 如果我删除“圆形”,我会收到 3.9123458543845474586。有没有办法只显示 3.9 和 .4,.2 等而无需四舍五入?我知道它一定是一个语法问题。当我删除回合时,我收到一个错误。

round((total_qty)*((avg_qty/(sum(avg_qty)over(partition by ID)))/5),0) avg_qty

round((total_qty)*((avg_qty/(sum(avg_qty)over(partition by ID)))/5),0) avg_qty

Thanks in advance.

提前致谢。

采纳答案by Dba

Try like this,

试试这样,

SELECT ROUND(3.9123458543845474586, 1) Round FROM DUAL;

     Round
----------
      3.9

For better understanding please refer this link.

为了更好地理解,请参阅此链接

回答by GriffeyDog

If you always want to "round" down, the function is trunc. This should work for you:

如果你总是想“圆圆”,该功能trunc。这应该适合你:

select trunc(3.99999, 1) from dual;

Result

结果

3.9