1

I am using following syntax to display a value in a proper number format, e.g. 1,250.00.

<s:property value="%{getText('{0,number,#,##0.00}',#plan.amount)}" />

However, it is not working. The plan is an object with a property amount.

Roman C
  • 49,761
  • 33
  • 66
  • 176
JJN
  • 69
  • 1
  • 9
  • What value is printed to the out? – Roman C Mar 07 '16 at 21:36
  • The databeing displayed is 1250.00 without the the comma. – JJN Mar 07 '16 at 23:01
  • @AleksandrM It's not true. – Roman C Mar 08 '16 at 11:49
  • @AleksandrM It's not clear what is the type of list. I suspect that it doesn't work with *all* lists. I will wait for good solution of my question or delete it because no interest from the community. – Roman C Mar 08 '16 at 11:56
  • @AleksandrM I have explained it enough, if you understand this question, then you should understand my question, the difference only to understand my answer below you have to put some effort to understand the problem. And it congrats you afterwords. – Roman C Mar 08 '16 at 12:03
  • @VikramSingh *The pound sign (#) denotes a digit, the comma is a placeholder for the grouping separator, and the period is a placeholder for the decimal separator.*. – Aleksandr M Mar 08 '16 at 15:05

2 Answers2

1

First of all, if you want to display multiple values from a list, you need an iterator;

second, if plan is a list in the action with a getter method

public List<Something> getPlan() { return plan; }

then you don't have to put the # ahead of the variable.

The right code for your case would be:

<s:iterator value="plan">
    <s:property value="getText('{0,number,#,##0.00}',{amount})" />
</s:iterator>

There's a related Q&A on the topic.


EDIT

Since you have

<s:iterator value="list" var="plan" status="status"> 
    <div class="values"> 
        $ <s:property value="%{getText('{0,number,#,##0.00}',#plan.amount)}"/> 
    </div>
</s:iterator>

Then it should be:

<s:iterator value="list">
    <s:property value="getText('{0,number,#,##0.00}',{amount})" />
</s:iterator>
Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
0

If the value is printed like 1250.00 then it's not formatted properly. The method getText() has many overloaded methods and which method is used is determined by the parameter's types and count.

To pass arguments to the getText() method you can use OGNL list construction {}. And the arguments should be listed as single values, not "list of object". Perfectly it should be list of Double with one element inside the list.

<s:set var="amount" value="%{1250.0}"/>
<s:property value="%{getText('{0,number,#,##0.00}',{#amount})}" />
Roman C
  • 49,761
  • 33
  • 66
  • 176