Subject Re: casting to decimal(9,2) gives different answers if used with a group by clause
Author wibbleian2
--- In firebird-support@yahoogroups.com, "emb_blaster" <EMB_Blaster@...> wrote:
>
> 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?).
>

Summing after rounding is always going to give you a different [and IMO wrong!] answer.

round(1.5+1.5) = 3
round(1.5) + round(1.5) = 4

Not that surprising!

Ian