| | |
| | | return price.multiply(percent).divide(PERCENT_100, PRICE_SCALE, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | /** |
| | | * 计算含税总价里的税额(单价为含税单价时使用) |
| | | * |
| | | * 税额 = 含税总价 × 税率 ÷(100 + 税率) |
| | | * 例如:含税总价 113.00,税率 13% → 税额 13.00 |
| | | * |
| | | * @param totalPriceWithTax 含税总价 |
| | | * @param taxPercent 税率,例如 13% 传入 13 |
| | | * @return 税额;含税总价为空时返回 null,税率为空或非正数时返回 0.00 |
| | | */ |
| | | public static BigDecimal priceCalculateTaxIncluded(BigDecimal totalPriceWithTax, BigDecimal taxPercent) { |
| | | if (totalPriceWithTax == null) { |
| | | return null; |
| | | } |
| | | if (taxPercent == null || taxPercent.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return BigDecimal.ZERO.setScale(PRICE_SCALE, RoundingMode.HALF_UP); |
| | | } |
| | | return totalPriceWithTax.multiply(taxPercent) |
| | | .divide(PERCENT_100.add(taxPercent), PRICE_SCALE, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | /** |
| | | * 含税总价拆出不含税金额 |
| | | * |
| | | * 不含税金额 = 含税总价 − 税额(税额见 {@link #priceCalculateTaxIncluded}) |
| | | * |
| | | * @param totalPriceWithTax 含税总价 |
| | | * @param taxPercent 税率,例如 13% 传入 13 |
| | | * @return 不含税金额;含税总价为空时返回 null |
| | | */ |
| | | public static BigDecimal priceExcludeTax(BigDecimal totalPriceWithTax, BigDecimal taxPercent) { |
| | | BigDecimal taxPrice = priceCalculateTaxIncluded(totalPriceWithTax, taxPercent); |
| | | if (taxPrice == null) { |
| | | return null; |
| | | } |
| | | return totalPriceWithTax.subtract(taxPrice).setScale(PRICE_SCALE, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | } |