xain
xain

Reputation: 13839

Problem with variable inside gsp

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.

Upvotes: 1

Views: 3477

Answers (1)

leebutts
leebutts

Reputation: 4882

What does total end up being?

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

Try

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

Upvotes: 3

Related Questions