I want to format some numbers in our jsp pages.
first i define some resources in my porperties
format.number.with2Decimal={0,number,#0.00}
......
Question1:
i want to know what is the ‘#’ and '0' means?
0.00,#0.00,##.00,###0.00
who can tell me the differences between them? thanks!
Question2:
if i define a BigDecimal type in my action
BigDecimal number1;
Then my page should using a format to show this value,
1.if number1=null then show -NIL-
2.if number1=0 then show -NIL-
3.if number1>0 then show 1.00,3434.98 .....
please ignore number<0
Question3:
change number1 to a String,
1.if number1=null or empty or blank then show -NIL-
2.if number1=Hello then show Hello ....
could you give me help?
0
means that a number must be printed, no matter if it exists#
means that a number must be printed if it exists, omitted otherwise.Example:
Running Example
Output:
In Struts2, you can apply this kind of format with the
getText()
function fromActionSupport
.P.S: Question 2 and 3 are trivial (and messy).
Here you go :
This is how I format numbers in my projects. You can use it with
<s:if>
to attain what you require.