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

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

trunc and round function in sql

sqloracletruncateroundingnegative-number

提问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 roundand truncdo the same )

不,行为取决于有效数字的值(第三个数字(3)在您的情况下是重要的,因为它低于 5roundtrunc执行相同的操作)

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 truncand rounddiffer.

尝试select trunc(125456.76,-4) from dual(结果为 120000)与 select round(125456.76,-4) from dual(结果为 130000)。现在,当有效数字为 5(或更高)时,trunc和的结果round不同。

回答by Akash KC

ROUNDis related to round figure of given value.

ROUND与给定值的整数有关。

TRUNCis related to truncation of given values.

TRUNC与给定值的截断有关。

In roundcase of given example, four places till 4th place prior to decimal point padded with 0.

round给定示例的情况下,小数点前第四位的四位用 0 填充。

But in trunccase, four places till 4th place prior to decimal point replacd with 0.

trunc以防万一,小数点前第四位的四位用0代替。