Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Rounding up nearest ten, hundred etcby bobf (Monsignor) |
on Sep 27, 2004 at 16:53 UTC ( [id://394246]=note: print w/replies, xml ) | Need Help?? |
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.
In Section
Seekers of Perl Wisdom
|
|