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")In reply to RE: Round a Number to Any Place
by tye
in thread Round a Number to Any Place
by reptile
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |