Re: How to add commas to a number?



JerryP wrote:

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?

When you say that you "input" those numbers, exactly which code are you using to produce the above result?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages