Greetings DaWolf,
I pulled a lot of this from the Perl Cookbook. Essentually, it's just adding the commas as normal then swapping the comma a period. Depending on your needs for currency, you may want to keep the "sprintf" rounding to round off numbers to two decimal places (like the last element of @data).
#!/usr/bin/perl -w
use strict;
my @data = (
'36000.0000',
'12725.0000',
'80000',
'8123.2412'
);
sub fix_number {
my $number = shift;
$number = reverse sprintf("%.2f", $number);
$number =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
$number =~ tr/.,/,./;
return scalar reverse $number;
}
foreach (@data) {
print fix_number($_), "\n";
}
exit;
-gryphon
code('Perl') || die;