# 常见对象_BigDecimal的加减乘除法的使用

package cn.itcast_02;

import java.math.BigDecimal;

/*
* 构造方法:
* 		public BigDecimal(String val):
*
* 金融相关的东西(例:银行钱的小数,商品价格小数,实验小数)
*
* 成员方法:
* 		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) {
System.out.println(0.09 + 0.01);
System.out.println(1.0 - 0.32);
System.out.println(1.015 * 100);
System.out.println(1.301 / 100);

BigDecimal bd1 = new BigDecimal("0.09");
BigDecimal bd2 = new BigDecimal("0.01");
System.out.println("----------------------");
// public BigDecimal subtract(BigDecimal subtrahend):减
BigDecimal bd3 = new BigDecimal("1.0");
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");
System.out.println("multiply:" + bd5.multiply(bd6));
System.out.println("----------------------");
// public BigDecimal divide(BigDecimal divisor):除
BigDecimal bd7 = new BigDecimal("1.301");
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));
}
}


09-16 57万+
06-28 1万+
08-12 9028
11-07 11万+
07-13 1952
04-24 131
07-31 8万+
09-11 1594
12-13 4016
03-15 1444
06-29 681
06-02 644
08-01 9494