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!
> 0表示必须打印一个数字,无论它是否存在
>#表示必须打印一个数字(如果存在),否则省略.
例:
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("==============================");
输出:
06001
在Struts2中,您可以使用ActionSupport的getText()函数应用此类格式.
P.S:问题2和3是微不足道的(而且很混乱).