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

Re: printf with currency symbols

Thread Previous | Thread Next
Robert Citek
October 26, 2009 11:08
Re: printf with currency symbols
Message ID:
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.

- Robert

On Mon, Oct 26, 2009 at 11:57 AM, Bryan R Harris
<> 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About