public BigDecimal add(BigDecimal augend):加
public BigDecimal subtract(BigDecimal subtrahend):减
public BigDecimal multiply(BigDecimal multiplicand):乘
public BigDecimal divide(BigDecimal divisor):除
public BigDecimal divide(BigDecimal divisor,int scale,int roundingMode):商,几位小数,如何舍取。
public class BigDecimalDemo {
public static void main(String[] args) {// public BigDecimal add(BigDecimal augend):加
BigDecimal bd1 = new BigDecimal("10.12");
BigDecimal bd2 = new BigDecimal("10.01");
System.out.println("add:" + bd1.add(bd2));
System.out.println("----------------------");
// public BigDecimal subtract(BigDecimal subtrahend):减
BigDecimal bd3 = new BigDecimal("1.01");
BigDecimal bd4 = new BigDecimal("0.32");
System.out.println("subtract:" + bd3.subtract(bd4));
System.out.println("----------------------");
// public BigDecimal multiply(BigDecimal multiplicand):乘
BigDecimal bd5 = new BigDecimal("1.015");
BigDecimal bd6 = new BigDecimal("100.12");
System.out.println("multiply:" + bd5.multiply(bd6));
System.out.println("----------------------");
// public BigDecimal divide(BigDecimal divisor):除
BigDecimal bd7 = new BigDecimal("3.141");
BigDecimal bd8 = new BigDecimal("100");
System.out.println("divide:" + bd7.divide(bd8));
System.out.println("divide:" + bd7.divide(bd8,3,BigDecimal.ROUND_HALF_UP));
System.out.println("divide:" + bd7.divide(bd8,9,BigDecimal.ROUND_HALF_UP));
}
BigDecimal.ONE//值为 1,标度为 0
BigDecimal.ZERO//值为 0,标度为 0
BigDecimal.TEN//值为 10,标度为 0
BigDecimal.ROUND_HALF_UP//向“最接近的”数字舍入,如果与两个相邻数字的距离相等,则为向上舍入的舍入模式
。。。。。
具体详见JDK API