To all the Monks here who might remember my past questions, I think I'm getting better... but yet again another question... This is my output file:
data data data data 7,843,391.58 xyz xzy xyz .... 12,224,675.68 abc ~~~ ~~~ .... 1,339,203.94 (more data) 21,407,271.2 (more data) 16,728,929.69 16,728,929.69
The following code is what I used; was taken from the Q and A section (thanks vroom) to insert commas.
sub addcommas{ my ($text)= $nocomma; $text=reverse $text; $text=~s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; $text=scalar reverse $text; return $text; }
My question/s is/are how can I: - align to the right the final column w/ the dollar amounts? (when printing out.. this is the end of a string print with other data left out for this example) or align the decimals? and - how to stop from dropping the end zero of the cents, where it's missing? This is my print statement how I got my final printout (where $comma is the returned variable caught from the above function):
for ($p = 0; $p < @a_table; $p++){ @a_print = split (/\t/, $a_table[$p]); $nocomma = $a_print[5] / 100; $comma = &addcommas(); print AUDIT "$a_print[0]\t$a_print[1]\t$read_time\t$a_print[3] +\t$comma\n"; } # end for loop
My final output is all correct, just the problems w/alignment and the loss of zero at end of cents... thanks for any/all help.

In reply to Decimal alignment and loss of zero at print? by Zo

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.