Thank you Rob this helps allot and should do the trick.

Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  ----- Original Message ----- 
  From: Rob Dixon 
  To: Perl Beginners 
  Cc: Mike Blezien 
  Sent: Sunday, February 12, 2012 10:46 AM
  Subject: Re: Formatting Numbers


  On 12/02/2012 16:14, Mike Blezien wrote:
  >
  > Need a little assistance formatting numbers pulled from a databaes. Many
  > are like this:
  >
  > 179550, 45960, 890458 etc.
  >
  > what I need to do is format these values with a comma so they look like
  > this:
  >
  > 179,550, 45,960, 890,458
  >
  > What is the easiest way to do this?

  Hi Mike

  I suggest the subtitution s/(\d+?)(?=(\d{3})+\b)/$1,/g which looks for
  all sequences of digits that are followed by a multiple of three digits
  and puts a comma after each of them. The program below illustrates this.

  HTH,

  Rob


  use strict;
  use warnings;

  for (qw/ 179550 45960 890458 -12345678 1000000000000/) {
     (my $n = $_) =~ s/(\d+?)(?=(\d{3})+\b)/$1,/g;
     print "$n\n";
  }

  **OUTPUT**

  179,550
  45,960
  890,458
  -12,345,678
  1,000,000,000,000

Reply via email to