java中针对BigDecimal 类型字段处理
加 add
BigDecimal bignum1 = new BigDecimal("10");
BigDecimal bignum2 = new BigDecimal("5");
System.out.println("和 是:" + bignum1.add(bignum2));
减 subtract
BigDecimal bignum1 = new BigDecimal("10");
BigDecimal bignum2 = new BigDecimal("5");
System.out.println("差 是:" + bignum1.subtract(bignum2));
乘 multiply
BigDecimal bignum1 = new BigDecimal("10");
BigDecimal bignum2 = new BigDecimal("5");
System.out.println("积 是:" + bignum1.multiply(bignum2));
除 divide
BigDecimal bignum1 = new BigDecimal("10");
BigDecimal bignum2 = new BigDecimal("5");
System.out.println("商 是:" + bignum1.divide(bignum2));
四舍五入后保留两位小数 setScale
BigDecimal bignum1 = new BigDecimal("10.2536");
System.out.println("商 是:" + bignum1.setScale(2, BigDecimal.ROUND_HALF_UP));