http://qs321.pair.com?node_id=11128548

pgmer6809 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to write a report and have the decimal points in the various numbers line up properly. But using say %4.2f or % 4.2f or %04.2f all have the same problem when the value in question is zero. Is there a format spec that will fix this?

 perl -e'$fmt="\n%3d : %04.2f : %3d";printf $fmt,3,12.34,-1;printf $fmt,2,00.00,1;print "\n";'

Result

3 : 12.34 : -1 2 : 0.00 : 1

Replies are listed 'Best First'.
Re: Line up cols using printf %m.nf
by pryrt (Abbot) on Feb 19, 2021 at 02:37 UTC
    12.34 has five characters, not four, so to line up, you need %5.2f