| Author |
bean:write format string as number
|
Damian Lopez
Greenhorn
Joined: Jul 26, 2005
Posts: 17
|
|
Hi, in a jsp i am displaying some numeric bean properties (all of them are strings) and i would like to know how could i apply a format to them. The problem is that <bean:write name="bean" property="p" format="###.##"/> does not work because it is a string so it doesn�t get formatted, any ideas? Thanks.
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
I'd suggest adding a second getter for the field that converts the String to a number. Something like this: Then in your JSP you can code: <bean:write name="bean" property="fooAsFloat" format="###.##"/>
|
Merrill
Consultant, Sima Solutions
|
 |
Damian Lopez
Greenhorn
Joined: Jul 26, 2005
Posts: 17
|
|
|
Thanks, finally i am using new DecimalFormat(String x).format(float y) to format all the properties before refreshing the jsp
|
 |
K Sathya Narayanan
Greenhorn
Joined: Feb 15, 2007
Posts: 28
|
|
hi i used the below code but it is not getting formatetd <bean:write name="bandwidthModel" property="bytes" format="<%=new DecimalFormat("####,##").format(0)%>" /></td> please suggest me a code that can format the <bean:write name="bandwidthModel" property="bytes"> in this "####,##" format thanks in advance
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
You're working too hard. The format attribute should contain a simple String indicating how to format the number. Change your code to: Just make sure that the bytes property contains a number (float, double, etc.) rather than a String or other data type. If it doesn't, convert it to a numeric data type in the getter as I demonstrated in a previous post.
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: bean:write format string as number
|
|
|