如何计算百分比变化、差值和增减
百分比计算无处不在:营收增长 23%,CPU 使用率下降 15%,一个数字占另一个数字的多少百分比。公式本身简单,但术语容易混淆——"百分比变化"和"百分比差值"含义不同,搞错了结果就会出错。
百分比变化(增加或减少)
用于将旧值与新值进行比较。结果为正表示增加,为负表示减少。
百分比变化 = ((新值 - 旧值) / |旧值|) × 100
示例:
- 营收从 80,000 增至 100,000 → ((100,000 - 80,000) / 80,000) × 100 = +25%
- 用户数从 500 降至 400 → ((400 - 500) / 500) × 100 = -20%
function percentageChange(oldValue, newValue) {
return ((newValue - oldValue) / Math.abs(oldValue)) * 100;
}
console.log(percentageChange(80000, 100000).toFixed(2)); // 25.00
console.log(percentageChange(500, 400).toFixed(2)); // -20.00
def percentage_change(old, new):
return ((new - old) / abs(old)) * 100
print(f"{percentage_change(80000, 100000):.2f}%") # 25.00%
print(f"{percentage_change(500, 400):.2f}%") # -20.00%
Excel 公式:
=(B1-A1)/ABS(A1)*100
其中 A1 是旧值,B1 是新值。
为什么用 |旧值|(绝对值)? 如果旧值为负数(例如亏损转盈利),取绝对值才能得到正确的符号。
百分比差值(两值之间,无方向)
用于在没有明确"前后"关系时比较两个值——例如比较两家门店、两个国家或两款产品。结果始终为正。
百分比差值 = (|值1 - 值2| / ((值1 + 值2) / 2)) × 100
示例:门店 A 售出 120 件,门店 B 售出 80 件。百分比差值为:
(|120 - 80| / ((120 + 80) / 2)) × 100 = (40 / 100) × 100 = 40%
function percentageDifference(a, b) {
return (Math.abs(a - b) / ((a + b) / 2)) * 100;
}
console.log(percentageDifference(120, 80).toFixed(2)); // 40.00
def percentage_difference(a, b):
return (abs(a - b) / ((a + b) / 2)) * 100
print(f"{percentage_difference(120, 80):.2f}%") # 40.00%
如何选择:
- "Q2 销售额比 Q1 增长了" → 百分比变化(有前后之分)
- "A 地区 vs B 地区" → 百分比差值(对称,无方向)
占总量的百分比
百分比 = (部分 / 总量) × 100
示例:
- 200 名学生中 45 人通过 → (45 / 200) × 100 = 22.5%
- 15,000 元预算中花了 3,500 元 → (3,500 / 15,000) × 100 = 23.3%
function percentageOf(part, total) {
return (part / total) * 100;
}
console.log(percentageOf(45, 200).toFixed(1)); // 22.5
console.log(percentageOf(3500, 15000).toFixed(1)); // 23.3
def percentage_of(part, total):
return (part / total) * 100
print(f"{percentage_of(45, 200):.1f}%") # 22.5%
print(f"{percentage_of(3500, 15000):.1f}%") # 23.3%
Excel:
=A1/B1*100
或将单元格格式设为百分比(Excel 会自动乘以 100):
=A1/B1
从百分比还原原始值
已知百分比变化后的结果,需要反推原始值。
原始值 = 结果 / (1 + 百分比/100) ← 增加之后
原始值 = 结果 / (1 - 百分比/100) ← 减少之后
示例:产品加价 30% 后售价 130 元,原始成本:
130 / (1 + 30/100) = 130 / 1.30 = 100 元
function originalAfterIncrease(result, percent) {
return result / (1 + percent / 100);
}
function originalAfterDecrease(result, percent) {
return result / (1 - percent / 100);
}
console.log(originalAfterIncrease(130, 30)); // 100
console.log(originalAfterDecrease(85, 15)); // 100
百分点 vs 百分比
两者不同,容易混淆。
利率从 2% 上涨到 5%:
- 百分点变化为 3 pp(5 - 2 = 3)。
- 百分比变化为 150%((5 - 2) / 2 × 100 = 150%)。
两者都正确,但衡量的东西不同。"百分点"是两个百分比之间的绝对算术差值,"百分比变化"是相对变化。
复合百分比变化
百分比变化不能相加,而是复合叠加。涨 10% 再跌 10%,结果不等于原值。
100 × 1.10 × 0.90 = 99
function compoundChange(percentages) {
return percentages.reduce((acc, p) => acc * (1 + p / 100), 1) - 1;
}
// +10% 后 -10%
console.log((compoundChange([10, -10]) * 100).toFixed(2)); // -1.00%
// 连续三年 +20%
console.log((compoundChange([20, 20, 20]) * 100).toFixed(2)); // 72.80%
要点总结
- 百分比变化:
((新值 - 旧值) / |旧值|) × 100——有前后对比时使用。 - 百分比差值:
(|a - b| / 平均值) × 100——对称比较两个值时使用。 - 占总量百分比:
(部分 / 总量) × 100——最常见的情形。 - 百分点和百分比不是同一回事。
- 百分比变化会复合叠加——涨 10% 再跌 10% 净亏 1%。