sql中的trunc和round函数 [英] trunc and round function in sql

查看:203
本文介绍了sql中的trunc和round函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用否定参数将trunc和round取整吗?

Is trunc and round the same with negative arguments?

       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

推荐答案

否,行为取决于有效数字的值(在您的情况下,第3个数字(3)是有效数字,因为它低于5 roundtrunc相同)

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 )

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

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.

这篇关于sql中的trunc和round函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆