I am trying to make the decimal points line up in print statements like below. But when printing a zero value it only prints 3 digits as 0.00, and the decimal points don't line up. I have tried % 4.2f, %04.2f, %-4.2f and %4.2f but nothing works. Is there a way?

#!/usr/bin/perl $myfmt="%3d : %4.2f : %3d\n"; printf $myfmt, 111,12.34,-1; printf $myfmt, 22,0.00, -2; printf $myfmt, -2,-6.25, -3; =pod 111 : 12.34 : -1 22 : 0.00 : -2 -2 : -6.25 : -3 =cut
Thanks to the people who answered and pointed out the simple fix to my 'problem'. pgmer6809

In reply to Printf format --Solved Thanks by pgmer6809

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.