public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("###.##");
BigDecimal b1 = new BigDecimal("28.0109");
BigDecimal b2 = new BigDecimal("28.00");
System.out.println("小数格式化:" + df.format(b1));
System.out.println("整数格式化:" + df.format(b2));
}
本文通过一个Java示例展示了如何使用DecimalFormat类来格式化BigDecimal对象,以实现对小数和整数的精确显示。该示例适用于需要进行数值格式化处理的Java应用程序。
1017

被折叠的 条评论
为什么被折叠?



