On 1/4/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Let's say I have the following numbers and I want to print them out so they
> are formatted in money terms:

Have you seen this sub? It's from p. 184 of the llama book (Learning
Perl, 4th ed.).

 sub big_money {
    my $number = sprintf "%.2f", shift @_;
    # Add one comma each time through the do-nothing loop
    1 while $number =~ s/^(-?\d+)(\d\d\d)/$1,$2/;
    # Put the dollar sign in the right place
    $number =~ s/^(-?)/$1\$/;
    $number;
  }

That turns 12345678.9 into "$12,345,678.90". Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to