How to add commas to a number?



Hi!

I am trying to get this to work, but I am not having any luck?

use strict;
use warnings;

sub commify {
local($_) = shift;
1 while s/^(-?\d+)(\d{3})/$1,$2/;
return $_;
}

If I input these numbers:

6238.12
121150.98
104903.30
113569.26
40239.51
8733.55

I get :

6238.12
121150.98
104903.30
113569.26
40,239.51
8,733.55

Any ideas?

Thanks

Jerry

.



Relevant Pages