🛠️ToolsShed

割引計算機

セール価格・割引額・節約額を即座に計算。

割引計算機は、割引率が適用された後の販売価格を即座に計算したり、元の価格と販売価格が与えられた場合に受けている割引率を教えます。セールを評価する買い物客、プロモーション価格を設定する小売業者、異なる店舗のオファーを比較する人に役立ちます。

元の価格と割引率を入力すると、節約額と最終価格が表示されます。または元の価格と販売価格を入力して節約パーセンテージを計算します。最初の割引の上に2番目の割引を適用する必要がある場合、複数割引の積み重ねも処理します。

20%割引は価格が元の20%という意味ではありません — 80%を支払うという意味です。この違いは割引を重ねる際に重要です:2つの20%割引は60%ではなく元の価格の64%(0.8 × 0.8 = 0.64)を支払う結果になります。

よくある質問

コード実装

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.