Gossamer Forum
Quote Reply
Comma in the count
How would I put a comma in grandtotal when the count is over a thousand, hundred thousand, etc. As it is now the total looks like 120540. I would like to put in a comma so it would look like 120,540. I am not good at coding, and clueless on how this may be done, if it can be done at all.

Quote Reply
Re: [jgkiefer] Comma in the count In reply to
From the perl faq you can use:

Code:
sub commify {
local $_ = shift;
return 0 unless defined $_;
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
return $_;
}

and if you pass call commify(120540) it will return 120,450.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Comma in the count In reply to
I'm sorry I haden't realised there was a perl forum. I reviewed the threads regarding the comma thing, but I dont understand where the code snippet should go?

BTW -it might be my imagination, but this forum seems to have increased in speed. It loads like lightening.

Quote Reply
Re: [jgkiefer] Comma in the count In reply to
Hi,

You would want to do something like:

grand_total_formatted =>
Code:
sub {
my $tags = shift;
local $_ = $tags->{grand_total};
return 0 unless defined $_;
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
return $_;
}

and add that into your template globals. Then replace <%grand_total%> with <%grand_total_formatted%> in your template.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Comma in the count In reply to
Thanks Alex.
I mistakenly thought you wanted me to ask this in the Perl forum. I apologize for any disruption I may have inadvertently caused there.
Frown
Quote Reply
Re: [Alex] Comma in the count In reply to
What about the category grand total?

I'm using a global called "total_cats" with the following:

Code:
sub {
my $cat_db = $DB->table('Category');
my $count = $cat_db->count();
return $count;
}

Sean

Last edited by:

SeanP: Nov 2, 2001, 9:23 AM
Quote Reply
Re: [SeanP] Comma in the count In reply to
Thanks for reminding me about the categories... Wink

BTW, while we're on the subject...
How do you put a comma in the Number_of_Links displayed next to the category name??
Crazy

Thanks-

Quote Reply
Re: [SeanP] Comma in the count In reply to
Actually, to display the category totals with commas, you can add a global called total_cats_formatted with the following:

Code:
sub {
local $_ = $DB->table ('Category')->total;
return 0 unless defined $_;
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
return $_;
}


Sean
Quote Reply
Re: [jgkiefer] Comma in the count In reply to
Quote:
How do you put a comma in the Number_of_Links displayed next to the category name??

Try:

Code:
sub {
my $tags = shift;
local $_ = $tags->{Number_of_Links};
return 0 unless defined $_;
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
return $_;
}
Anyone seeing the pattern? ;)

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Comma in the count In reply to
Thanks-
I see the pattern but don't understand it. Coding is not my strong point.
Quote Reply
Re: [Alex] Comma in the count In reply to
Hi,

I can understand the change to globals and then change the tag in the template in order to put the comma in the total number of links, however, I am lost at how to do it for category1 (123,456). What template should be changed as I am not sure how to change the tags here to generate the outcome above.

Thanks.
Webmaster
http://www.e-bannerx.com
Quote Reply
Re: [fulcan] Comma in the count In reply to
Hi,

Add a global called Number_Formatted:

sub {
my $tags = shift;
local $_ = $tags->{Number_of_Links};
return 0 unless defined $_;
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
return $_;
}

then edit subcategory.html and replace <%Number_of_Links%> with <%Number_Formatted%>.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Comma in the count In reply to
Thanks Alex greatly appreciated.
Webmaster
http://www.e-bannerx.com