Why not FP for Money?

Carlos Ribeiro carribeiro at gmail.com
Wed Sep 22 11:51:42 EDT 2004


On Wed, 22 Sep 2004 17:51:30 +0300, Christos TZOTZIOY Georgiou
<tzot at sil-tec.gr> wrote:
> On 21 Sep 2004 17:11:22 -0700, rumours say that danb_83 at yahoo.com (Dan
> Bishop) might have written:
> 
> >But what about countries like Japan and (even more so) Turkey where
> >the currency units are so small that you never use fractions of them?
> >Do programmers there talk less about floating-point error?
> 
> This used to be the case in Greece too; however, there was and still is
> VAT (amount * 0.08 or 0.18), discounts, distribution of a "gross"[1]
> discount ("your invoice is over 200000 drachmae, so I'll give you a
> 20000 drs discount") over the items of an invoice (and the "gross"
> discount should equal the sum of qty*discount_per_item) etc.

Beware! Floating point errors may bite you *even for non-fractional
numbers*. Once the number of significant digits is bigger than the
precision of the mantissa, there will be automatic scaling of values,
dropping the least significant digit(s). Depending on the floating
point representation (single, double or extended, just to mention the
most common ones), this error will happen with numbers of different
magnitudes (from ~7 to ~19 significant digits, depending upon the
internal representation, if I remember it well). This error is
particularly nasty if you're repeatedly summing large quantities with
small ones.


-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com



More information about the Python-list mailing list