BigDecimal a= new BigDecimal("10");
BigDecimal b= new BigDecimal("5");
BigDecimal c= null;
1.加法-add
c
=
a.add(
b)
.setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println("求和:"
+
c);
2.减法-subtract
c
=
a.subtract(
b)
.setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println("求差:"
+
c);
3.乘法-multiply
c
=
a.multiply(
b)
.setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println("乘法积:"
+
c);
4.除法-divide
c
=
a.divide(
b)
.setScale(2, BigDecimal.ROUND_HALF_UP);
c = a.divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP)
System.out.println("除法结果:"
+
c);
5.整数舍弃零
DecimalFormat df = new DecimalFormat("###.##"); df.format(new BigDecimal(88.88))------>输出结果:88.88 df.format(new BigDecimal(66.00))------>输出结果:66
相关文章
暂无评论...