Adding commas to numbers

KevinADC 0 Tallied Votes 252 Views Share

Convert 1000000 into 1,000,000 using a perl regexp.

my $number - 1000000;
$number = commify($number);

sub commify {
   (my $num = shift) =~ s/\G(\d{1,3})(?=(?:\d\d\d)+(?:\.|$))/$1,/g; 
   return $num; 
KevinADC 192 Practically a Posting Shark

In the above code the first line should be:

my $number = 1000000;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.