You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bhaarat Sharma <bh...@gmail.com> on 2009/05/05 20:57:33 UTC

how to format a percentage

I have the following in my properties file:
format.percent = {0,number,##0.00'%'}

But the following code doesnt work and always gives 0.00%

<s:text name="format.percent"><s:param value="%{( (50 / 200) *
100)}"/></s:text>
...evaluates to <s:text name="format.percent"><s:param value="%{( (.25) *
100)}"/></s:text>



However, the following code does work...

<s:text name="format.percent"><s:param value="%{( (200 / 50) *
100)}"/></s:text>
...evaluates to <s:text name="format.percent"><s:param value="%{( (4) *
100)}"/></s:text>

What is going on here? why dont decimals work?

Re: how to format a percentage

Posted by Steven Yang <ke...@gmail.com>.
have you tried<s:text name="format.percent"><s:param value="%{( (50.0 /
200.0) *100.0)}"/></s:text>

without the decimal OGNL might treat your numbers as integers and there for
you get 0.

I havent test it out but thats what I used to do for JSTL