Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying Data

 
Prasath Thirumoorthy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

Im working in Struts Project.In my TransferObject the data type of an attribute(Say Market Price) is Double.While populating the values from database its displaying the data in the jsp with Exponential like 1.82684971E8

How to Avoid the E8 user doesnt want to show this in the Jsp.

Thanks in Advance

Cheers,
Prasath
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

<bean:write name="myBean" property="myDouble" formatKey="" />

This will write the number using the default number format for the locale.
 
Prasath Thirumoorthy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Merrill Higginson ,

Ya its working fine.Thank u very much.

Here is the piece of code what I used.
**************************************************************************
In my JSP:

<bean:write name="myBean" property="myDouble" formatKey="currencyFormat"/>
**************************************************************************
In my Resource Bundle:I added
currencyFormat = #,##0.00
**************************************************************************

Now The format is in US.But now I Need to customize the format according to type of Currency like USD, CLP, EUR, GBP...How can i do this.
Please kindly give me some idea..

Thanks in Advance

Cheers,
Prasath
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the type of currency used is always tied to the locale of the user, you could simply create an ApplicationResources_xx_xx.properties files for each locale and put the appropriate currency symbol in the currencyFormat key for each of these properties files.

See this link for an explanation of how Struts handles resource bundles for internationalization.

If you can't always tie the currency to the locale, you will have to create a new getter for the bean (for example: getFormattedAmount) in which you put your own logic to format the amount with the appropriate currency symbol. In the JSP, you would then just write:

<bean:write name="myBean" property="formattedAmount" />
[ March 14, 2006: Message edited by: Merrill Higginson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic