我想在我们的jsp页面中格式化一些数字。 首先,我定义了一些资源 format.number.with2Decimal={0,number,#0.00}
format.number.with2Decimal={0,number,#0.00}
...... 问题1: 我想知道“#”和“ 0”的含义是什么? 0.00,#0.00,##。00,### 0.00 谁能告诉我它们之间的区别?谢谢!
问题2: 如果我在动作BigDecimal number1中定义了BigDecimal类型;
然后我的页面应该使用一种格式来显示此值, 1.if number1=null then show -NIL- 2.if number1=0 then show -NIL- 3.if number1>0 then show 1.00,3434.98 ..... 请忽略number <0
1.if number1=null then show -NIL-
2.if number1=0 then show -NIL-
3.if number1>0 then show 1.00,3434.98 .....
问题3: 将number1更改为String, 1.if number1=null or empty or blank then show -NIL- 2.if number1=Hello then show Hello ....
1.if number1=null or empty or blank then show -NIL-
2.if number1=Hello then show Hello ....
你能帮我吗?
问题1:我想知道“ #”和“ 0”的含义是什么? 0.00,#0.00,##.00,###0.00谁可以告诉我他们之间的区别是什么?谢谢!
#
0
0.00
#0.00
##.00
###0.00
例:
System.out.println("Assuming US Locale: " + "',' as thousand separator, " + "'.' as decimal separator "); NumberFormat nf = new DecimalFormat("#,##0.0##"); System.out.println("\n=============================="); System.out.println("With Format (#,##0.0##) "); System.out.println("------------------------------"); System.out.println("1234.0 = " + nf.format(1234.0)); System.out.println("123.4 = " + nf.format(123.4)); System.out.println("12.34 = " + nf.format(12.34)); System.out.println("1.234 = " + nf.format(1.234)); System.out.println("=============================="); nf = new DecimalFormat("#,000.000"); System.out.println("\n=============================="); System.out.println("With Format (#,000.000) "); System.out.println("------------------------------"); System.out.println("1234.0 = " + nf.format(1234.0)); System.out.println("123.4 = " + nf.format(123.4)); System.out.println("12.34 = " + nf.format(12.34)); System.out.println("1.234 = " + nf.format(1.234)); System.out.println("==============================");
[**Running Example**](http://ideone.com/goqADm)
输出:
Assuming US Locale: ',' as thousand separator, '.' as decimal separator) ============================== With Format (#,##0.0##) ------------------------------ 1234.0 = 1,234.0 123.4 = 123.4 12.34 = 12.34 1.234 = 1.234 ============================== ============================== With Format (#,000.000) ------------------------------ 1234.0 = 1,234.000 123.4 = 123.400 12.34 = 012.340 1.234 = 001.234 ==============================
在Struts2中,您可以使用中的getText()函数来应用这种格式ActionSupport。
getText()
ActionSupport
PS:问题2和3很琐碎(而且很混乱)。