gaoluyang
2026-11-04 fbaeeeff5704f210bc6347454c0f16d255001822
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java
@@ -9,7 +9,7 @@
/**
 * 金额工具类
 *
 * @author 芋道源码
 * @author 超级管理员
 */
public class MoneyUtils {
@@ -128,4 +128,24 @@
        return price.multiply(percent).divide(PERCENT_100, PRICE_SCALE, RoundingMode.HALF_UP);
    }
    /**
     * 计算含税金额中包含的税额
     *
     * 适用场景:单价为含税单价时,价税合计 = 单价 * 数量,税额 = 价税合计 * 税率 / (100 + 税率)。
     * 例如:含税金额 113 元、税率 13%,税额为 13 元。
     *
     * 位数:{@link #PRICE_SCALE}
     *
     * @param totalPrice 含税金额(价税合计)
     * @param percent    税率,百分比
     * @return 含税金额中的税额
     */
    public static BigDecimal taxPriceIncluded(BigDecimal totalPrice, BigDecimal percent) {
        if (totalPrice == null || percent == null || percent.compareTo(BigDecimal.ZERO) <= 0) {
            return null;
        }
        return totalPrice.multiply(percent)
                .divide(PERCENT_100.add(percent), PRICE_SCALE, RoundingMode.HALF_UP);
    }
}