SPUG: Working with currency

Jack Foy jack at foys.net
Thu Apr 2 18:48:11 PDT 2009


Colin Meyer wrote:
> If they are trying to do money calculations, and are not worried
> about converting between foreign currencies, then the quick answer
> is to do all calculations in pennies, as integers, and only convert
> to dollars when displaying. This avoids propagating floating point
> rounding errors. The long answer is quite ... well, longer. There's 
> lots on the web about calculations with money.

This may be part of your longer answer: wouldn't integer calculations in
fractional cents (to two or three decimal places) be closer to a
real-world solution?

-- 
Jack Foy <jack at foys.net>


More information about the spug-list mailing list