# Rounding off - PERL Beginners

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 ?? TIA -- Mike<mickalo>Blezien =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Thunder Rain Internet Publishing Providing Internet Solutions that work! [url]http://www.thunder-rain.com[/url] Quality Web Hosting [url]http://www.justlightening.net[/url] MSN: [email]mickalothunder-rain.com[/email] =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=...

1. ## Rounding off

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

TIA
--
Mike<mickalo>Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
[url]http://www.thunder-rain.com[/url]
Quality Web Hosting
[url]http://www.justlightening.net[/url]
MSN: [email]mickalothunder-rain.com[/email]
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Mike Blezien Guest

2. ## Re: Rounding off

--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
---------------------------------------------------------------
Daniel Staal Guest

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•