You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by akoo <og...@yahoo.com> on 2009/05/01 19:01:57 UTC

number formatting (with commas)

Hi guys, 
I have looked through all of the documentations and am just not having any
success formatting numbers (i.e 70333 -> 70,333)  so I thought i'd ask you
guys.  here are relevant snippets of my code.

  <s:iterator value="positions">
<tr>

              <td><s:property value="account"/> </td>
              <td ><s:property value="symbol"/> </td>
              <td><s:text name="format.number"><s:param name="value"
value="netpl"></s:param></s:text></td>
</tr>

Positions in the above code is a list of position objects 
class Position
{
    private String symbol;
    private String account;
    private float netpl;
    //followed by getters and setters for all of the above field
}

The Action class FirmwidePositionAction  returns the list of positions after
querying the the database

What I want is for the netpl number to show up formatted properly with the
comma placeholders and a 'USD' prefix,  so I created the package.properties
file and placed it in the same package as the action class.
Here is my package.properties file

format.time = {0,time}
format.number = USD{0,number,##0.00}
format.percent = {0,number,##0.00'%'}
format.money = {0,number,\u00A4##0.00}


The numbers all show up perfectly. However, I am not able to get the 'USD'
to appear in front of the netpl columns.  What am I doing wrong here?

Thanks

-- 
View this message in context: http://www.nabble.com/number-formatting-%28with-commas%29-tp23336400p23336400.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: number formatting (with commas)

Posted by Zoran Avtarovski <zo...@sparecreative.com>.
Wouldn¹t the appropriate currency symbol be in the locale properties? I
expect you would have a separate package.properties file for each locale.

Z.
> 
> akoo wrote:
>> > I am not sure actually, it was just an example I pulled the roseindia site.
>> > This is all quite new to me.
> 
> (Be wary of roseindia tutorials.)
> 
> Chris is right; it's just a positional parameter--not sure what I was
> thinking when I wrote my original response.
> 
> Dave
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 



Re: number formatting (with commas)

Posted by Dave Newton <ne...@yahoo.com>.
akoo wrote:
> I am not sure actually, it was just an example I pulled the roseindia site. 
> This is all quite new to me.

(Be wary of roseindia tutorials.)

Chris is right; it's just a positional parameter--not sure what I was 
thinking when I wrote my original response.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: number formatting (with commas)

Posted by akoo <og...@yahoo.com>.
I am not sure actually, it was just an example I pulled the roseindia site. 
This is all quite new to me.


newton.dave wrote:
> 
> akoo wrote:
>> format.number = USD{0,number,##0.00}
> 
> Is it possible to specify characters outside of the format string like 
> that? It's not how you've formatted the money type:
> 
>> format.money = {0,number,\u00A4##0.00}
> 
> Dave
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/number-formatting-%28with-commas%29-tp23336400p23338657.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: number formatting (with commas)

Posted by Chris Pratt <th...@gmail.com>.
Since the purpose of the <s:text> tag is to allow things like:

error.message=User {0} has not been granted permission to view that page

<s:text name="error.message"><s:param value="%{user.id}"/></s:text>

I don't see how having USD outside of the curly braces would be a problem,
but just in case it is, you might try:

format.money={0,number,'USD'###,##0.00}

Also try something like:

format.money=This is rediculous

to make sure it's picking up the properties file you think it is.
  (*Chris*)

On Fri, May 1, 2009 at 11:52 AM, Dave Newton <ne...@yahoo.com> wrote:

> akoo wrote:
>
>> format.number = USD{0,number,##0.00}
>>
>
> Is it possible to specify characters outside of the format string like
> that? It's not how you've formatted the money type:
>
>  format.money = {0,number,\u00A4##0.00}
>>
>
> Dave
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: number formatting (with commas)

Posted by Dave Newton <ne...@yahoo.com>.
akoo wrote:
> format.number = USD{0,number,##0.00}

Is it possible to specify characters outside of the format string like 
that? It's not how you've formatted the money type:

> format.money = {0,number,\u00A4##0.00}

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: number formatting (with commas)

Posted by Burton Rhodes <bu...@gmail.com>.
Guess it would help if I read your entire email ;)

How about this:

format.number= {0,number,\u00A4###,##0}

-or-

format.number= {0,number,'USD'###,##0}

On Fri, May 1, 2009 at 1:26 PM, Burton Rhodes <bu...@gmail.com> wrote:
> I solved it this way:
>
> <s:textfield key="netpl" value="%{getText('format.money',netpl)}" />
>
> Then in your class path put a file called package.properties with the following:
>
> # used to format dates, numbers in the jsp files (display)
> format.time = {0,time}
> format.dateShort = {0,date,MM/dd/yyyy}
> format.number = {0,number,###,##0.0##}
> format.percent = {0,number,##0.00'%'}
> format.money = {0,number,\u00A4###,##0}
> format.moneyDecimal = {0,number,\u00A4###,##0.00}
>
>
> On Fri, May 1, 2009 at 12:01 PM, akoo <og...@yahoo.com> wrote:
>>
>> Hi guys,
>> I have looked through all of the documentations and am just not having any
>> success formatting numbers (i.e 70333 -> 70,333)  so I thought i'd ask you
>> guys.  here are relevant snippets of my code.
>>
>>  <s:iterator value="positions">
>> <tr>
>>
>>              <td><s:property value="account"/> </td>
>>              <td ><s:property value="symbol"/> </td>
>>              <td><s:text name="format.number"><s:param name="value"
>> value="netpl"></s:param></s:text></td>
>> </tr>
>>
>> Positions in the above code is a list of position objects
>> class Position
>> {
>>    private String symbol;
>>    private String account;
>>    private float netpl;
>>    //followed by getters and setters for all of the above field
>> }
>>
>> The Action class FirmwidePositionAction  returns the list of positions after
>> querying the the database
>>
>> What I want is for the netpl number to show up formatted properly with the
>> comma placeholders and a 'USD' prefix,  so I created the package.properties
>> file and placed it in the same package as the action class.
>> Here is my package.properties file
>>
>> format.time = {0,time}
>> format.number = USD{0,number,##0.00}
>> format.percent = {0,number,##0.00'%'}
>> format.money = {0,number,\u00A4##0.00}
>>
>>
>> The numbers all show up perfectly. However, I am not able to get the 'USD'
>> to appear in front of the netpl columns.  What am I doing wrong here?
>>
>> Thanks
>>
>> --
>> View this message in context: http://www.nabble.com/number-formatting-%28with-commas%29-tp23336400p23336400.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: number formatting (with commas)

Posted by Bhaarat Sharma <bh...@gmail.com>.
wont "format.money = {0,number,\u00A4###,##0}" automatically add a '$' sign
in front of the number?

On Fri, May 1, 2009 at 2:26 PM, Burton Rhodes <bu...@gmail.com>wrote:

> I solved it this way:
>
> <s:textfield key="netpl" value="%{getText('format.money',netpl)}" />
>
> Then in your class path put a file called package.properties with the
> following:
>
> # used to format dates, numbers in the jsp files (display)
> format.time = {0,time}
> format.dateShort = {0,date,MM/dd/yyyy}
> format.number = {0,number,###,##0.0##}
> format.percent = {0,number,##0.00'%'}
> format.money = {0,number,\u00A4###,##0}
> format.moneyDecimal = {0,number,\u00A4###,##0.00}
>
>
> On Fri, May 1, 2009 at 12:01 PM, akoo <og...@yahoo.com> wrote:
> >
> > Hi guys,
> > I have looked through all of the documentations and am just not having
> any
> > success formatting numbers (i.e 70333 -> 70,333)  so I thought i'd ask
> you
> > guys.  here are relevant snippets of my code.
> >
> >  <s:iterator value="positions">
> > <tr>
> >
> >              <td><s:property value="account"/> </td>
> >              <td ><s:property value="symbol"/> </td>
> >              <td><s:text name="format.number"><s:param name="value"
> > value="netpl"></s:param></s:text></td>
> > </tr>
> >
> > Positions in the above code is a list of position objects
> > class Position
> > {
> >    private String symbol;
> >    private String account;
> >    private float netpl;
> >    //followed by getters and setters for all of the above field
> > }
> >
> > The Action class FirmwidePositionAction  returns the list of positions
> after
> > querying the the database
> >
> > What I want is for the netpl number to show up formatted properly with
> the
> > comma placeholders and a 'USD' prefix,  so I created the
> package.properties
> > file and placed it in the same package as the action class.
> > Here is my package.properties file
> >
> > format.time = {0,time}
> > format.number = USD{0,number,##0.00}
> > format.percent = {0,number,##0.00'%'}
> > format.money = {0,number,\u00A4##0.00}
> >
> >
> > The numbers all show up perfectly. However, I am not able to get the
> 'USD'
> > to appear in front of the netpl columns.  What am I doing wrong here?
> >
> > Thanks
> >
> > --
> > View this message in context:
> http://www.nabble.com/number-formatting-%28with-commas%29-tp23336400p23336400.html
> > Sent from the Struts - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: number formatting (with commas)

Posted by Burton Rhodes <bu...@gmail.com>.
I solved it this way:

<s:textfield key="netpl" value="%{getText('format.money',netpl)}" />

Then in your class path put a file called package.properties with the following:

# used to format dates, numbers in the jsp files (display)
format.time = {0,time}
format.dateShort = {0,date,MM/dd/yyyy}
format.number = {0,number,###,##0.0##}
format.percent = {0,number,##0.00'%'}
format.money = {0,number,\u00A4###,##0}
format.moneyDecimal = {0,number,\u00A4###,##0.00}


On Fri, May 1, 2009 at 12:01 PM, akoo <og...@yahoo.com> wrote:
>
> Hi guys,
> I have looked through all of the documentations and am just not having any
> success formatting numbers (i.e 70333 -> 70,333)  so I thought i'd ask you
> guys.  here are relevant snippets of my code.
>
>  <s:iterator value="positions">
> <tr>
>
>              <td><s:property value="account"/> </td>
>              <td ><s:property value="symbol"/> </td>
>              <td><s:text name="format.number"><s:param name="value"
> value="netpl"></s:param></s:text></td>
> </tr>
>
> Positions in the above code is a list of position objects
> class Position
> {
>    private String symbol;
>    private String account;
>    private float netpl;
>    //followed by getters and setters for all of the above field
> }
>
> The Action class FirmwidePositionAction  returns the list of positions after
> querying the the database
>
> What I want is for the netpl number to show up formatted properly with the
> comma placeholders and a 'USD' prefix,  so I created the package.properties
> file and placed it in the same package as the action class.
> Here is my package.properties file
>
> format.time = {0,time}
> format.number = USD{0,number,##0.00}
> format.percent = {0,number,##0.00'%'}
> format.money = {0,number,\u00A4##0.00}
>
>
> The numbers all show up perfectly. However, I am not able to get the 'USD'
> to appear in front of the netpl columns.  What am I doing wrong here?
>
> Thanks
>
> --
> View this message in context: http://www.nabble.com/number-formatting-%28with-commas%29-tp23336400p23336400.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org