Need to handle negative numbers as well. How about this?
#!/usr/bin/perl my $value = .23456; my $formatted = sprintf("%.3f", $value); $formatted =~ s/([^0-9])0\./$1./; print "$value => $formatted\n"; $value = $formatted = -.23456; $formatted = sprintf("%.3f", $value); $formatted =~ s/([^0-9])0\./$1./; print "$value => $formatted\n";
In reply to Re^4: Can sprintf suppress leading zero for float < 1?
by Anonymous Monk
in thread Can sprintf suppress leading zero for float < 1?
by RotoValue
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |