java - How can I format this string that represents decimal number in my JSP page? -
i have following problem. working on jsp page use jquery.
in page show money amounts table, this:
<td width = "8.33%"> <%=saldettaglio.gettotimponibile().tostring() != null ? saldettaglio.gettotimponibile().tostring() : "" %> </td>
the obtained object (from gettotimponibile() method) bigdecimal
in td of table shown value as: 447.93.
now have format amount in following way:
use , character instead . (for decimal digits).
show 2 decimal digits after . example can have 1 decimal digit 10,4 , have show 10,40 or can have more 2 decimal digits , in case have show firs 2 decimal digits (for example 10,432 have show 10,43)
so can achieve these 2 tasks? showing string represent decimal number. have cast value double or this?
first create class (i.e. numberformat.java) , please put following methods in numberformat.java class:
public static string pricewithdecimal (double price) { decimalformat formatter = new decimalformat("###,###,###.00"); return formatter.format(price); } public static string pricewithoutdecimal (double price) { decimalformat formatter = new decimalformat("###,###,###.##"); return formatter.format(price); }
now, in jsp use code this:
<td width = "8.33%"> <%=saldettaglio.gettotimponibile().tostring() != null ? numberformat.pricewithdecimal(double.parsedouble(saldettaglio.gettotimponibile().tostring())) : "" %> </td>
this solution work you.
Comments
Post a Comment