/***
* 数值计算方法
*/
public enum formula{
ADD(){
@Override
public BigDecimal getResult(BigDecimal price1 ,BigDecimal price2) {
return price1.add(price2);
}
},SUBTRACT(){
@Override
public BigDecimal getResult(BigDecimal price1 ,BigDecimal price2) {
return price1.subtract(price2);
}
},MULTIPLY(){
@Override
public BigDecimal getResult(BigDecimal price1 ,BigDecimal price2) {
return price1.multiply(price2);
}
},DIVIDE(){
@Override
public BigDecimal getResult(BigDecimal price1 ,BigDecimal price2) {
MathContext mc = new MathContext(3, RoundingMode.HALF_UP);
return price1.divide(price2,mc);
}
};
public abstract BigDecimal getResult(BigDecimal price1 ,BigDecimal price2);
}