in reply to Round a Number to Any Place
Nice work. Here are, I think, two improvements:
sub round { my( $num, $prec )= @_; return int( $num/$prec + 0.5 - ($num<0) ) * $prec; }
This is slightly simpler and rounds negative numbers properly.
- tye (but my friends call me "Tye")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE (2): Round a Number to Any Place
by nuance (Hermit) on Aug 30, 2000 at 00:09 UTC |