Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Calculation Display on Templates

Quote Reply
Calculation Display on Templates
Hi-

I'm trying to get a value to display on a template that is one field multiplied by another field.

I saw that you can do something like:

<%Hits * 5%>

and that would return '50' if the value of Hits was 10. My question is whether it's possible to have two variables in the calculation such as:

<%Hits * Rate%>

When I tried this it didn't seem to work. Does anyone know if this is possible and what the proper syntax would be?

--Jack Walter



Quote Reply
Re: Calculation Display on Templates In reply to
Hi,

You could try:

<%Hits * $Rate%>

I think that will work..

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Calculation Display on Templates In reply to
Thanks very much that worked :)

Not to get greedy, but is there any way to get it to show two decimal places? In other words, if the Hits were 7 and the Rate was .20, the result is displayed as 1.40 rather than 1.4?

Quote Reply
Re: Calculation Display on Templates In reply to
I'm not 100% sure how to do it but you may have to use sprintf

sprintf("%.2f", ($VAR * $VAR));

May require a new tag ?

Mods:http://wiredon.net/gt/download.shtml
Installs:http://wiredon.net/gt/


Quote Reply
Re: Calculation Display on Templates In reply to
Hi,

Going to be easier to make it global:

calculation => sub { my $tags = shift; return sprintf ("%.2f", $tags->{Hits} * $tags->{Rate}); }

and then use <%calculation%>.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Calculation Display on Templates In reply to
Excellent. Thanks very much for the help!