Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Change Display of Numbers to Include Commas

Quote Reply
Change Display of Numbers to Include Commas
When I list # of links within categories or beside "Hits" on my site, when we're into four our more digits, it doesn't show commas (e.g., 5000 instead of 5,000).

Is there a simple way to change the display so that commas are inserted as appropriate?
Quote Reply
Re: [Jobu] Change Display of Numbers to Include Commas In reply to
create a new global, like 'add_comma', with the following value:

Code:
sub {
my $num = shift;
$num = reverse join ",", grep { ! /^$/ } split /(\d{3})/, reverse $num;
return $num;
}

Then in your templates, you can do:
Code:
<%add_comma($Hits)%>

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Change Display of Numbers to Include Commas In reply to
Thanks!