Subject Re: [firebird-support] Re: casting to decimal(9,2) gives different answers if used with a group by clause
Author Kjell Rilbe
wibbleian2 wrote:
> > OK, so how many decimal places do the added terms require? 4? Cast to
> > that precision, then:
>
> The precision of the calculation is not the problem. The problem is that
> I have one piece of code that for a given parent does:

Yes, it is. The problem is that your calculation using double suffers
from rounding errors in the intermediate results, caused by the inherent
imprecision of all floating point datatypes. See my other post.

> I also have stashed in my head that "group by" appears to do some
> internal rounding that I wasn't expecting so I wont be surprised if this
> happens again. I wont like it if it does, but I wont be surprised. This
> is the general solution to my question. If you can call it a solution.

It is a solution, because that unexpected rounding is not unexpected.
It's an always-present aspect of doing calculations with an approximate
datatype such as double. Again, see my other post.

> Obviously the other solution is to persuade customers that the result of
> multiplying lots of precise numbers together and then rounding
> arbitrarily in different places will give you rounding errors that can
> be comfortably ignored. But I've not met a user that can be persuaded of
> anything, so I'll go back to waiting for the revolution.

That is just silly (no offence meant). Start by making sure you
understand how floating point calculations work. Then make sure you
don't use them in the wrong places, which is exctly what you're doing.

I hope my other post helps you understand what's going on and that
nothing's wrong, magic, buggy or anything like that.

Kjell
--
--------------------------------------
Kjell Rilbe
DataDIA AB
E-post: kjell@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64