Compare two items to find the best value per gallon.
Product A
Gallons
Fluid Ounces (fl oz)
Quarts
Pints
Liters
Product B
Gallons
Fluid Ounces (fl oz)
Quarts
Pints
Liters
function calculateCPG() {
var priceA = parseFloat(document.getElementById('priceA').value);
var volA = parseFloat(document.getElementById('volumeA').value);
var unitA = parseFloat(document.getElementById('unitA').value);
var priceB = parseFloat(document.getElementById('priceB').value);
var volB = parseFloat(document.getElementById('volumeB').value);
var unitB = parseFloat(document.getElementById('unitB').value);
var resultDiv = document.getElementById('cpgResult');
var resA = document.getElementById('resA');
var resB = document.getElementById('resB');
var winnerDiv = document.getElementById('cpgWinner');
if (isNaN(priceA) || isNaN(volA) || volA 0) {
var gallonsB = volB * unitB;
cpgB = priceB / gallonsB;
resB.innerHTML = "Product B Cost: $" + cpgB.toFixed(2) + " per gallon";
resB.style.display = "block";
hasB = true;
} else {
resB.style.display = "none";
winnerDiv.style.display = "none";
}
if (hasB) {
var diff = Math.abs(cpgA – cpgB);
var pct = (diff / Math.max(cpgA, cpgB)) * 100;
if (cpgA < cpgB) {
winnerDiv.innerHTML = "Product A is the winner! (Saves " + pct.toFixed(1) + "%)";
} else if (cpgB < cpgA) {
winnerDiv.innerHTML = "Product B is the winner! (Saves " + pct.toFixed(1) + "%)";
} else {
winnerDiv.innerHTML = "Both products have the same value!";
}
winnerDiv.style.display = "block";
}
resultDiv.style.display = "block";
}
Understanding Cost Per Gallon: The Key to Smarter Shopping
Whether you are at the gas pump, buying bulk milk for a restaurant, or choosing pool chemicals, the "Cost Per Gallon" is the most reliable metric to determine true value. Marketing often hides the real price behind odd packaging sizes; our calculator breaks through the noise to show you exactly what you are paying for every 128 fluid ounces.
Why Calculate Cost Per Gallon?
Retailers frequently use different units of measurement to make price comparisons difficult for consumers. A 5-liter jug of cleaner might look like a better deal than a 1-gallon bottle, but without converting to a common unit, you could be overpaying. By calculating the cost per gallon, you standardize the price, allowing for an "apples-to-apples" comparison.
Bulk Buying: Large containers aren't always cheaper. Sometimes two small bottles on sale beat one bulk tub.
Gasoline & Fuel: Tracking your cost per gallon over time helps in budgeting for long-haul transport or commuting.
Home Improvement: Comparing paint prices across different brands and container sizes (quarts vs. gallons).
The Cost Per Gallon Formula
The math behind the calculation is straightforward:
Cost Per Gallon = Total Price / Total Gallons
If your product is measured in ounces, you must first convert it to gallons. Since there are 128 fluid ounces in a US gallon, the formula becomes:
Cost Per Gallon = Total Price / (Total Ounces / 128)
Practical Examples
Example 1: Milk Comparison
Imagine you are at the grocery store. Product A is a full gallon of milk for $4.50. Product B is a half-gallon (64 oz) for $2.50.
Product A: $4.50 / 1 Gallon = $4.50 per gallon
Product B: $2.50 / 0.5 Gallons = $5.00 per gallon
In this case, buying the full gallon saves you $0.50 per gallon.
Example 2: Industrial Paint
A contractor is looking at a 5-gallon bucket of primer for $85.00 versus individual 1-gallon cans for $19.00 each.
5-Gallon Bucket: $85 / 5 = $17.00 per gallon
1-Gallon Can: $19 / 1 = $19.00 per gallon
The bulk bucket saves the contractor $2.00 for every gallon purchased.