问题1:我想知道“
#”和“0”的含义是什么?0.00,#0.00,##.00,###0.00谁可以告诉我他们之间的区别是什么?谢谢!
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("==============================");
[**Running Example**](http://ideone.com/goqADm)
输出:
Assuming US Locale: ',' as thousand separator, '.' as decimal separator)==============================With Format (#,##0.0##)------------------------------1234.0 = 1,234.0123.4 = 123.412.34 = 12.341.234 = 1.234============================================================With Format (#,000.000)------------------------------1234.0 = 1,234.000123.4 = 123.40012.34 = 012.3401.234 = 001.234==============================
在Struts2中,您可以使用中的
getText()函数来应用这种格式
ActionSupport。
PS:问题2和3很琐碎(而且很混乱)。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)