in reply to Can sprintf suppress leading zero for float < 1?
I don't think this is possible within sprintf. All floating point numbers have to have a digit before the decimal point.
The standard for printf family of functions states:
f, F
The double argument is rounded and converted to decimal notation in the style -ddd.ddd, where the number of digits after the decimal-point character is equal to the precision specification. If the precision is missing, it is taken as 6; if the precision is explicitly zero, no decimal-point character appears. If a decimal point appears, at least one digit appears before it.
Not too difficult to do with a quick regex or something, though.
$str =~ s/^0\./\./;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can sprintf suppress leading zero for float < 1?
by ambrus (Abbot) on Apr 13, 2012 at 21:11 UTC | |
by JavaFan (Canon) on Apr 14, 2012 at 02:00 UTC | |
by temporal (Pilgrim) on Apr 15, 2012 at 04:32 UTC | |
|
Re^2: Can sprintf suppress leading zero for float < 1?
by RotoValue (Initiate) on Apr 14, 2012 at 01:31 UTC | |
by roboticus (Chancellor) on Apr 14, 2012 at 12:11 UTC | |
by ikegami (Patriarch) on Apr 15, 2012 at 00:34 UTC | |
by roboticus (Chancellor) on Apr 16, 2012 at 14:02 UTC |