SPUG: Working with currency

Tye McQueen tyemq at cpan.org
Thu Apr 2 19:17:17 PDT 2009


On Thu, Apr 2, 2009 at 6:48 PM, Jack Foy <jack at foys.net> wrote:

> 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?


No, you want to do calculations in units of pennies and round to the nearest
penny (using banker's rounding) whenever you calculate a value that will be
displayed to the customer (unless you are displaying values other than to
the nearest penny, which is rare but not unheard of).

And you make these calculation in floating point, which is what Perl does
even if you use int() (but don't "use integer;").

Tye
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/spug-list/attachments/20090402/64eadda6/attachment.html>


More information about the spug-list mailing list