java - format double value to two decimal places in EL expression in jsp -


how can format double value salary 2 decimal places in %{emp.salary}

code in jsp page below

<input type='text' name='salary' value='<s:property value="%{emp.salary}"/>' /> 

i know how in servlet/pojo classes , send correctly. question how on jsp page inside el expression.

also know not best way . want know if can done.

you can use bellow code number format :

<fmt:formatnumber type="number" maxfractiondigits="2" value="${emp.salary}" /> 

but if want use s:property way help.

<s:property value="gettext('{0,number,#,##0.00}',{emp.salary})"/> 

for curious mind udaybhaskar.

how find gettext() solution:

frankly speaking didn't tried learn them tried found solutoion. example in case format double number. knew need to use nested tag.
like:

<s:property value="somethig/ possiblly tag format"/>

i find out <s:text> text formating. go there . in search of like. <s:property value="<s:text name="?" />"/>

if go bottom find out suggestion (a little one) saying use gettext(). actaully method in actionsupportclass of struts. actionsupport

there many version of gettext().

in <s:text> documentation page recommend see messageformat. because gettext() use messageformat format text. go messageformat , try understand patterns , interpretation .

and gel them together.

so once again dint learn find out.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -