Subtract the two values: difference = A − B
Convert to absolute value if you want a non-negative result: abs_difference = |A − B|
Choose the denominator:
Percent difference (symmetric): percent_difference = (|A − B| / ((A + B) / 2)) × 100
Percent change (from B to A): percent_change = ((A − B) / B) × 100
Compute the ratio and multiply by 100 to get the percentage
Handle edge cases:
If using percent change and B = 0, percent change is undefined (or not meaningful)
If using percent difference and A + B = 0, percent difference is undefined (or not meaningful)
