sub roundoff { my $num = shift; my $roundto = shift || 1; return int($num/$roundto+0.5)*$roundto; } foreach my $i (0.6, 1.2, 38.4, 88.6, 92.5) { printf "%5.1f ",$i; foreach my $j (1, 10, 100) { printf "%2d ", roundoff($i,$j); } print "\n"; }