sub formatCurrency {
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\$/;
return $number;
}
Friday, October 10, 2008
Perl : Formatting a number to currency format
Posted by Vishnu Agrawal at 10:12 PM
Labels: perl script
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment