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

Hi everyone. τΏτ

I'm new to pearl and I need to output a mysql price list into an html table. This was no problem but how do I add a "$" to the front of the prices in the table? or convert the floating point number to a currency?

Any help would be very much appreciated. Thank you.

Replies are listed 'Best First'.
Re: converting to a currency
by valdez (Monsignor) on May 10, 2003 at 12:29 UTC

    A possible solution is Math::Currency:

    use Math::Currency qw(Money $LC_MONETARY); Math::Currency->format( $LC_MONETARY->{EUR} ); Math::Currency->format('MON_THOUSANDS_SEP', '\''); print Math::Currency::Money(12345.67);

    this code prints €12'345,67. Your question was thoroughly answered here: Making money look nice.

    Ciao, Valerio

      Thanks heaps. I'll give it a try.
Re: converting to a currency
by castaway (Parson) on May 10, 2003 at 11:17 UTC
    Using sprintf, would be my guess:
    my $curr = sprintf("$%.2f", $value);

    C.

      This line of code has a small error in it... it should be my $curr = sprintf("\$%.2f", $value); It works fine after that. Scubaelmo "It's kind of fun to do the impossible.." Walt Disney