APM: Question: breaking up a numeric variable
Chris Stansbury
ChrisS at natlplan.com
Thu Sep 26 14:14:08 CDT 2002
Use the commify sub below; taken from Perl cookbook.
sub commify {
# from Perl Cookbook, page 64
# add commas for pretty printing numbers
my $text = reverse $_[0];
$text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
return scalar reverse $text;
}
Chris
Goldilox wrote:
>Is there a good way to take a numeric variable of undetermined length
>
>$var=3423723482309234098;
>$var2=3325656;
>etc.
>and print it out with a comma appropriately placed at every third character
>slot from the end, i.e.
>
>3,423,723,482,309,234,098
>3,325,656
>etc.
>
>Rhett
>
>_______________________________________________
>Austin mailing list
>Austin at mail.pm.org
>http://mail.pm.org/mailman/listinfo/austin
>
>
>
>
--
******************************
Chris Stansbury
Systems Administrator
ChrisS at natlplan.com
wrk: 512-327-6481
internet fax 630-839-2619
www.natlplan.com
National Plan Administrators
******************************
More information about the Austin
mailing list