Adding commas to numbers

KevinADC KevinADC is offline Offline Sep 3rd, 2006, 1:26 am |
0
Convert 1000000 into 1,000,000 using a perl regexp.
Quick reply to this message  
Perl Syntax
  1. my $number - 1000000;
  2. $number = commify($number);
  3.  
  4. sub commify {
  5. (my $num = shift) =~ s/\G(\d{1,3})(?=(?:\d\d\d)+(?:\.|$))/$1,/g;
  6. return $num;
  7. }
0
KevinADC KevinADC is offline Offline | Nov 18th, 2008
In the above code the first line should be:

my $number = 1000000;
 
 

Message:


Thread Tools Search this Thread



Tag cloud for Perl
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC