develooper Front page | perl.beginners | Postings from October 2009

Re: printf with currency symbols

Thread Previous | Thread Next
From:
Robert Citek
Date:
October 26, 2009 11:08
Subject:
Re: printf with currency symbols
Message ID:
4145b6790910260943s1f89c804sbdc2fb7a6e088903@mail.gmail.com
I see.  You want the output to look something like this:

$ perl -e 'for(my $total = 24.15; $total <30000; $total *= 10) {
printf("Total:%10s\n", "\$" . sprintf("%.2f",$total)) ;} '
Total:    $24.15
Total:   $241.50
Total:  $2415.00
Total: $24150.00

Not sure if there is a better way.  My guess is that there is probably
some module to convert float to currency and then print it as a
string.  But a quick Google didn't turn up anything.

Good luck and let us know how things go.

Regards,
- Robert

On Mon, Oct 26, 2009 at 11:57 AM, Bryan R Harris
<Bryan_R_Harris@raytheon.com> wrote:
> Is there a way to do this without getting all messy like this?
>
>  printf "Total:%10s\n", "\$".sprintf(%.2f,$total);

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About