Bracing against the wind  
www.documentroot.com  

Thursday, May 08, 2008

Perl Round Function

Yes, you can't find this easily on the web. What you get is people telling you to import posix, or do some wacky one-off thing that works half the time. This is the only solution you'll ever need... it should be a builtin.

# round to any decimal place
sub round {
my ($n,$d) = @_;
return int($n/(10**$d) + .5 * ($n <=> 0)) * (10**$d);
}

Labels: ,


[View/Post Comments] [Digg] [Del.icio.us] [Stumble]

Home | Email me when this weblog updates: | View Archive

(C) 2002 Erik Aronesty/DocumentRoot.Com. Right to copy, without attribution, is given freely to anyone for any reason.


Listed on BlogShares | Bloghop: the best pretty good | Blogarama | Technorati | Blogwise