BigDecimal op1=new BigDecimal("3.14159");
BigDecimal op2=new BigDecimal("3");
System.out.println("和="+op1.add(op2));
System.out.println("差="+op1.subtract(op2));
System.out.println("积="+op1.multiply(op1));
System.out.println("商="+op1.divide(op2, BigDecimal.ROUND_UP));
System.out.println("负值="+op1.negate());
System.out.println("指定精度的商="+op1.divide(op2,15, BigDecimal.ROUND_UP));
输出:
和=6.14159
差=0.14159
积=9.8695877281
商=1.04720
负值=-3.14159
指定精度的商=1.047196666666667