パーセント計算機
パーセント・変化率・チップ金額を計算。
パーセント計算機は、1つの数が別の数の何パーセントかを調べること、所与の値のパーセンテージを計算すること、パーセンテージがわかっているときの元の値を見つけること、2つの数の間のパーセンテージの増減を計算することなど、最も一般的なパーセンテージの問題を1つの使いやすいインターフェースで処理します。
必要な計算の種類を選択し、既知の値を入力すると、結果が即座に表示されます。逆算も可能です — 例えば、割引価格と割引率がわかれば、元の価格を知ることができます。
パーセント計算は小売割引とマークアップ、税金計算、財務リターン、成績計算、チップ計算、統計分析など、あらゆる場所で使用されます。
よくある質問
コード実装
def percentage_of(percent, total):
"""X% of Y"""
return total * percent / 100
def what_percent(part, total):
"""X is what % of Y"""
return (part / total) * 100 if total != 0 else 0
def percent_change(old_value, new_value):
"""Percentage change from old to new"""
return ((new_value - old_value) / old_value) * 100 if old_value != 0 else 0
def add_percent(value, percent):
"""Add X% to a value"""
return value * (1 + percent / 100)
def subtract_percent(value, percent):
"""Subtract X% from a value"""
return value * (1 - percent / 100)
# Examples
print(f"15% of 200: {percentage_of(15, 200)}")
print(f"30 is what % of 120: {what_percent(30, 120):.2f}%")
print(f"50 -> 75 change: {percent_change(50, 75):.2f}%")
print(f"100 + 20%: {add_percent(100, 20)}")
print(f"100 - 15%: {subtract_percent(100, 15)}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.