sub to_three_sig_digits { my $val = shift; if ($val =~ /^(0\.0*)(\d+)$/) { my $pre = $1; my $app = $2; return $val if length($app) <= 3; my $digits = substr($app, 0, 3); my $fourth = substr($app, 3, 1); $digits += 1 if $fourth >= 5; $val = $pre . $digits; } elsif ($val > 1) { $val = sprintf("%.2f", $val); } return $val; }