Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Rounding up nearest ten, hundred etc

by bobf (Monsignor)
on Sep 27, 2004 at 16:53 UTC ( [id://394246]=note: print w/replies, xml ) Need Help??


in reply to Rounding up nearest ten, hundred etc

As sgifford illustrated, you can use the int and sprintf functions to round to whole numbers. There is also the Math-Round module for rounding integers. The POSIX module has the ceil and floor functions, which you might want to tuck away for later.

BTW, sprintf can be used directly to round a number to a given number of decimal places. See perlfaq4, "Does Perl have a round() function?", for details.

HTH

Update: I see many other creative examples were posted in addition to sgifford's while I was distracted looking at Math-Round. If you want to roll your own, take your pick! :) The module looks interesting, though, specifically the nearest function.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://394246]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 02:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found