1

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.

1 Answer 1

3

What does total end up being?

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

Try

<g:set var="total" value="${0l}" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.