🛠️ToolsShed

折扣计算器

即时计算促销价格、折扣金额和节省金额。

折扣计算器即时计算应用百分比折扣后的售价,或在给定原价和售价的情况下告诉您正在获得的折扣百分比。对于评估优惠的购物者、制定促销价格的零售商以及任何跨不同商店比较报价的人都很有用。

输入原价和折扣百分比以查看节省金额和最终价格。或者输入原价和售价来计算节省的百分比。如果您需要在第一个折扣基础上再应用第二个折扣,该工具还处理多重折扣叠加。

20% 折扣并不意味着价格是原价的 20%——它意味着您支付 80%。这一区别在叠加折扣时很重要:两个 20% 的折扣结果是支付原价的 64%(0.8 × 0.8 = 0.64),而不是 60%。

常见问题

代码实现

def calculate_discount(original_price, discount_percent):
    """Calculate discounted price and savings."""
    discount_amount = original_price * (discount_percent / 100)
    final_price = original_price - discount_amount
    return {
        "original": original_price,
        "discount_amount": round(discount_amount, 2),
        "final_price": round(final_price, 2),
        "savings_percent": discount_percent,
    }

def calculate_discount_percent(original_price, sale_price):
    """Find the discount percentage from two prices."""
    return round(((original_price - sale_price) / original_price) * 100, 2)

def stack_discounts(original_price, *discounts):
    """Apply multiple discounts sequentially."""
    price = original_price
    for d in discounts:
        price *= (1 - d / 100)
    return round(price, 2)

# Examples
print(calculate_discount(80, 30))
print(calculate_discount_percent(50, 35))  # => 30.0%
print(stack_discounts(100, 20, 10))         # => 72.0 (not 70.0)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.