On Tue, Nov 08, 2005 at 01:50:35PM -0800, Andrew Lentvorski wrote:
...
> Also, if this is doing anything useful with money, use a language with a 
> Money or Decimal type.  Doing floating point math with monetary amounts 
> will be nothing but trouble.  The problem is that 1/10 is an inexact 
> repating decimal in binary floating point.
...
IMO, a more detailed answer would help.

There is a large body of knowledge about this issue.  Unfortunately
I'm not informed enough to go much beyond naming some of the issues.

Doing interest calculations or using other mathematical formulas
on monetary amounts can be trouble regardless of how numbers
are represented.  Every base will have its repeating "decimals" if
a variety of fractions are needed. You also can run out of precision
even if the decimal doesn't repeat, e.g. 1/1048576 needs 20 decimal
places.  Integer cents or base 10
sometimes help, but not always.  It is possible to do monetary
calculations reliably in binary floating point, but decimal sounds
much simpler if it's available and the variety of calculations
is limited to ones that are problem-free in decimal.  It's
worth remembering that floating point is exact for representing
integers below a size limit determined by precision.

Stewart Strait


-- 
KPLUG-List@kernel-panic.org
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to