in reply to Round a Number to Any Place
Oh, and don't bother debating the validity of rounding to the nearest even. I wasted several hours trying to do that the last time around.sub round { my( $num, $place )= @_; $num = $num/$place; my $calc = int( $num + 0.5 * ( $num <=> 0 ) ); $calc += (0 <=> $num) if( $calc % 2 and 0.5 == abs( int($num) - $n +um ) ); return $calc * $place }
NOTE: I think there is a bug in that code, but I'm tired and I couldn't place it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Round a Number to Any Place
by tye (Sage) on Aug 30, 2000 at 09:31 UTC | |
by Adam (Vicar) on Aug 30, 2000 at 20:29 UTC | |
by tye (Sage) on Aug 30, 2000 at 20:36 UTC | |
by Adam (Vicar) on Aug 30, 2000 at 20:37 UTC |