Price Comparison Calculator Formula

Understand the math behind the price comparison calculator. Each variable explained with a worked example.

Formulas Used

Product A Unit Price

unit_price_a = unit_a

Product B Unit Price

unit_price_b = unit_b

Price Difference

pct_difference = abs(unit_a - unit_b) / max(unit_a, unit_b) * 100

Variables

VariableDescriptionDefault
price_aProduct A Price(USD)3.99
qty_aProduct A Quantity6
price_bProduct B Price(USD)5.49
qty_bProduct B Quantity10
unit_aDerived value= price_a / qty_acalculated
unit_bDerived value= price_b / qty_bcalculated

How It Works

How to Compare Product Prices

Compute the unit price for each product, then see which is lower. The percentage difference tells you how much more expensive the pricier option is.

Formula

Unit Price = Total Price / Quantity

Difference % = |Unit A - Unit B| / max(Unit A, Unit B) x 100

Worked Example

Product A: 6-pack for $3.99 vs Product B: 10-pack for $5.49.

price_a = 3.99qty_a = 6price_b = 5.49qty_b = 10
  1. 01Product A unit price = $3.99 / 6 = $0.6650
  2. 02Product B unit price = $5.49 / 10 = $0.5490
  3. 03Product B is cheaper per unit
  4. 04Difference = |$0.6650 - $0.5490| / $0.6650 x 100 = 17.4%

Ready to run the numbers?

Open Price Comparison Calculator