floating or decimal for currency values

hi

Isnt it true that floating type can generate rounding errors if the
values are rounded to like the 10th decimal. Since currency is rounded
only to the 2nd decimal why must i worry about using float for currency
calculations?

decimal is slow and memory hog.

is it true that mysql calculates internally using double float?

Andy
anagai [ Mo, 25 April 2005 19:51 ] [ ID #762396 ]

Re: floating or decimal for currency values

<anagai [at] verizon.net> wrote in message
news:1114451487.559696.252780 [at] z14g2000cwz.googlegroups.com.. .
> hi
>
> Isnt it true that floating type can generate rounding errors if the
> values are rounded to like the 10th decimal.

Ti's true!
Floating point calculations *always* generate rounding errors. It's a
limitation we live with in order to gain the efficiency and large dynamic
range that floating point calculations offer.

> Since currency is rounded
> only to the 2nd decimal why must i worry about using float for currency
> calculations?

Because chains of calculation and complex arithmetic (interest
calculations!) that we often use erodes that safety margin rather quickly.
AND many accounting apps. need that last penny accuracy. Even though
working with millions of $ makes pennies seem insignificant - having things
work out to that last penny lends needed confidence to calculations. If you
are skimming the pennies into your personal account - use Float :-) If you
are looking for accounting accuracy, use Decimal.

> decimal is slow
Well - slower than float - perhaps!

> and memory hog.
Doubtful.

> is it true that mysql calculates internally using double float?
I don't know!

Thomas Bartkus
Thomas Bartkus [ Mo, 25 April 2005 22:12 ] [ ID #762398 ]
Datenbanken » mailing.database.mysql » floating or decimal for currency values

Vorheriges Thema: need sql help please...
Nächstes Thema: know how mangement database , script database tool