Subject | Re: casting to decimal(9,2) gives different answers if used with a group by clause |
---|---|
Author | wibbleian2 |
Post date | 2009-04-16T21:13:34Z |
--- In firebird-support@yahoogroups.com, "emb_blaster" <EMB_Blaster@...> wrote:
round(1.5+1.5) = 3
round(1.5) + round(1.5) = 4
Not that surprising!
Ian
>Summing after rounding is always going to give you a different [and IMO wrong!] answer.
> I think the problem is not realy *only* about the group by...
> Did you notice that "cast the sum" results diff than "sum the cast".
> Try the below SQL
>
> SQL> select sum(cast(qty as decimal(9,2))) from tmp;
> > CAST
> > ============
> >
> > 130.27
>
> I´m not good with FB internals work, so I let to anyone explain the diff in this case (maybe Helen?).
>
round(1.5+1.5) = 3
round(1.5) + round(1.5) = 4
Not that surprising!
Ian