sub tounit($$) { # pick parameters my($num, $unit) = @_; # check parameters return undef unless looks_like_number($num); return undef unless looks_like_number($unit); return $unit unless $unit; # edit # round number my $res = $unit * sprintf( '%.0f', $num / $unit ); # return rounded number return $res; } # tounit