in reply to Preferred Methods
Then you might want to be able to round to a specific place:sub round { my $n = shift; int($n + .5 * ($n < 0 ? -1 : 1)); }
Ta da. Now you can round 123.45678 to 123.457 by calling round(123.45678, 3), and you can round 123456789 to 123500000 by calling round(123456789, -5).sub round { my ($n, $p) = @_; $p ||= 0; # default to integer rounding int($n * 10**$p + .5 * ($n < 0 ? -1 : 1)) / 10**$p; }
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Preferred Methods
by theorbtwo (Prior) on Jan 14, 2002 at 22:31 UTC |