oracle sql中的trunc和round函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11304803/
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
trunc and round function in sql
提问by lakshganga
Is trunc and round the same with negative arguments?
trunc 和 round 是否与否定参数相同?
SQL> select round(123456.76,-4) from dual;
ROUND(123456.76,-4)
-------------------
120000
SQL> select trunc(123456.76,-4) from dual;
TRUNC(123456.76,-4)
-------------------
120000
回答by BertNase
No, behavior depends on the value of the significant digit (the 3rd digit (the 3) is the significant one in your case, as it is below 5 round
and trunc
do the same )
不,行为取决于有效数字的值(第三个数字(3)在您的情况下是重要的,因为它低于 5round
并trunc
执行相同的操作)
try select trunc(125456.76,-4) from dual
(result is 120000) vs select round(125456.76,-4) from dual
(result is 130000). Now when the significant digit is 5 (or higher) the results of trunc
and round
differ.
尝试select trunc(125456.76,-4) from dual
(结果为 120000)与 select round(125456.76,-4) from dual
(结果为 130000)。现在,当有效数字为 5(或更高)时,trunc
和的结果round
不同。
回答by Akash KC
ROUND
is related to round figure of given value.
ROUND
与给定值的整数有关。
TRUNC
is related to truncation of given values.
TRUNC
与给定值的截断有关。
In round
case of given example, four places till 4th place prior to decimal point padded with 0.
在round
给定示例的情况下,小数点前第四位的四位用 0 填充。
But in trunc
case, four places till 4th place prior to decimal point replacd with 0.
但trunc
以防万一,小数点前第四位的四位用0代替。