ERP:增加金额计算的四舍五入

This commit is contained in:
YunaiV
2024-02-07 10:34:23 +08:00
parent f6d3290426
commit 3479ef8123
2 changed files with 23 additions and 2 deletions

View File

@ -13,6 +13,11 @@ import java.math.RoundingMode;
*/
public class MoneyUtils {
/**
* 金额的小数位数
*/
private static final int PRICE_SCALE = 2;
/**
* 计算百分比金额,四舍五入
*
@ -86,4 +91,20 @@ public class MoneyUtils {
return new Money(0, fen).toString();
}
/**
* 金额相乘,默认进行四舍五入
*
* 位数:{@link #PRICE_SCALE}
*
* @param price 金额
* @param count 数量
* @return 金额相乘结果
*/
public static BigDecimal priceMultiply(BigDecimal price, BigDecimal count) {
if (price == null || count == null) {
return null;
}
return price.multiply(count).setScale(PRICE_SCALE, RoundingMode.HALF_UP);
}
}