--As off Saturday, November 22, 2003 4:27 PM -0600, Mike Blezien is alleged to have said:

Hello,

I need the ability to round off dollar amounts to the nearest 100th
of a dollar amount, IE $14.9564 to $14.96 or $132.1123 to $113.11

what is the best way to accomplish this ??

--As for the rest, it is mine.


Best way? Well, that depends...

A simple sprintf("%.2f", $num) will do initial rounding, but read 'perldoc -f round' for issues.

Slightly more flexible (and possibly more precise) is Math::Round, which can handle rounding in several different formats.

The question is, how precise do those numbers need to be? For a real financial application you probably need to write your own rounding routine, to be sure it acts exactly as you need it. If you just need to print out a few dollar figures, either of the above will probably do.

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to