How to sum values with Freemarker

5,812 views
Skip to first unread message

Roberto

unread,
Apr 23, 2012, 11:20:10 AM4/23/12
to runmyp...@googlegroups.com
Hello, I've a problem with this freemarker script:
<#if risultato?is_hash>
<#if risultato.row?exists>
                <#if risultato.row?is_sequence>
<#assign tmp = 0>
                        <#list risultato.row as x>
                             <#assign tmp = tmp+x.rank>
                        </#list>
                <#else>
                <#assign tmp = risultato.row.rank>
                </#if>
</#if>
<#else>
<#assign tmp="no match">
</#if>
${tmp}

I would like to sum values contained into the variable risultato.row.rank and store it into the variable tmp

The problem is that this instruction <#assign tmp = tmp+x.rank> treats the numbers as string... so the output is a concatenated string like: 102.98129128.129387123 where the two numbers are:
102.98129 and 128.129387123

Which is the right sintax?

Roberto

unread,
Apr 23, 2012, 11:24:26 AM4/23/12
to runmyp...@googlegroups.com
Solved:
The right sintax is:
                             <#assign tmp=tmp?number+x.rank?number>
Reply all
Reply to author
Forward
0 new messages