如何在oracle中使用2位小数进行汇总,如

如何在oracle中使用2位小数进行汇总,如,oracle,rounding,Oracle,Rounding,嗨,我有这样的要求,如四舍五入2位小数,如果我使用四舍五入函数,它得到四舍五入,但不会四舍五入,如果第三位小数小于5。 我的要求是小数点后的第三位和第二位应该四舍五入。可能吗 eg: 17.813 need to be 17.82 20.126 need to be 20.13 Select round(17.813,2) from dual will give 17.81 如何计算?您可以乘以100,将调整后的值“四舍五入”(某种程度上)到最接近的整数,然后再除以100: ceil(&l

嗨,我有这样的要求,如四舍五入2位小数,如果我使用四舍五入函数,它得到四舍五入,但不会四舍五入,如果第三位小数小于5。 我的要求是小数点后的第三位和第二位应该四舍五入。可能吗

eg: 17.813 need to be 17.82

20.126 need to be 20.13

Select round(17.813,2) from dual will give 17.81
如何计算?

您可以乘以100,将调整后的值“四舍五入”(某种程度上)到最接近的整数,然后再除以100:

ceil(<your number> * 100) / 100
使用(正数):

因此,您可以用如下类似的方式概括汇总版本:

ceil(n * power(10, integer)) * power(10, -integer)
您需要了解如何处理负值,尽管这可能已经是您想要的了;插入2作为“整数值”:

with t (n) as (
  select 17.813 from dual
  union all select 20.126 from dual
  union all select 1.000 from dual
  union all select 1.001 from dual
  union all select 1.005 from dual
  union all select 1.009 from dual
  union all select 1.010 from dual
  union all select -1.000 from dual
  union all select 0 from dual
  union all select -1.001 from dual
  union all select -1.005 from dual
  union all select -1.009 from dual
  union all select -1.010 from dual
)
select n, ceil(n * power(10, 2)) * power(10, -2) as rounded_up
from t;

         N ROUNDED_UP
---------- ----------
    17.813      17.82
    20.126      20.13
         1          1
     1.001       1.01
     1.005       1.01
     1.009       1.01
      1.01       1.01
        -1         -1
         0          0
    -1.001         -1
    -1.005         -1
    -1.009         -1
     -1.01      -1.01
ceil(n * power(10, integer)) * power(10, -integer)
with t (n) as (
  select 17.813 from dual
  union all select 20.126 from dual
  union all select 1.000 from dual
  union all select 1.001 from dual
  union all select 1.005 from dual
  union all select 1.009 from dual
  union all select 1.010 from dual
  union all select -1.000 from dual
  union all select 0 from dual
  union all select -1.001 from dual
  union all select -1.005 from dual
  union all select -1.009 from dual
  union all select -1.010 from dual
)
select n, ceil(n * power(10, 2)) * power(10, -2) as rounded_up
from t;

         N ROUNDED_UP
---------- ----------
    17.813      17.82
    20.126      20.13
         1          1
     1.001       1.01
     1.005       1.01
     1.009       1.01
      1.01       1.01
        -1         -1
         0          0
    -1.001         -1
    -1.005         -1
    -1.009         -1
     -1.01      -1.01