解决方法:
1
|
foo.divide(bar, 2 , BigDecimal.ROUND_HALF_UP); |
注意这个divide方法有两个重载的方法,一个是传两个参数的,一个是传三个参数的:
两个参数的方法:
@param divisor value by which this {@code BigDecimal} is to be divided. 传入除数
@param roundingMode rounding mode to apply. 传入round的模式
三个参数的方法:
@param divisor value by which this {@code BigDecimal} is to be divided. 传入除数
@param scale scale of the {@code BigDecimal} quotient to be returned. 传入精度
@param roundingMode rounding mode to apply. 传入round的模式