views:

54

answers:

1

Hi, I have a loop inside a gsp page, and I want to do a calculation on the fly, so I set a variable:

<g:set var="total" value="0" />

And in the loop:

<g:each in="${mob}" var="m">
  ...
   <g:set var="total" value="${total+(m.q*m.sts.uf)}"/>
  ...
</g:each>

The "total" value does not correspond to the expected calculation. m.q is an integer, and m.sts.uf is a float.

Any hints ?

Thanks.

A: 

What does total end up being?

It could be because total is being initialised as a String.

Try

<g:set var="total" value="${0l}" />
leebutts