我正在使用Java 1.6,我们正在使用java.text.DecimalFormat
格式化数字.例如
DecimalFormat df = new DecimalFormat();
df.setPositivePrefix("$");
df.setNegativePrefix("(".concat($));
df.setNegativeSuffix(")");
df.setMaximumFractionDigits(2);
df.setMinimumFractionDigits(2);
df.setGroupingSize(3);
df.format(new java.math.BigDecimal(100);
Run Code Online (Sandbox Code Playgroud)
每当传递null
值 时我的应用程序崩溃df.format(null)
Error: cannot format given object as a number
Run Code Online (Sandbox Code Playgroud)
我的问题是,我如何处理功能null
价值df.format()
?
我想将null传递给df.format()
函数,并希望它返回0.00
而不是上面的错误.
谢谢
问候,
Ankush
java ×1