trunc and round function in sql

后端 未结 2 377
你的背包
你的背包 2021-01-19 18:06

Is trunc and round the same with negative arguments?

       SQL> select round(123456.76,-4) from dual;

        ROUND(123456.76,-4)
         -------------         


        
相关标签:
2条回答
  • 2021-01-19 18:34

    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 )

    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.

    0 讨论(0)
  • 2021-01-19 18:38

    ROUND is related to round figure of given value.

    TRUNC is related to truncation of given values.

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

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

    0 讨论(0)
提交回复
热议问题