Calculate and compare unit rates to find the best value or efficiency.
Item A
The numerator (Price, Distance, Mass)
The denominator (Ounces, Hours, Count)
Item B (Comparison)
Compare against this item
Compare against this quantity
Comparison Results
Item A Unit Rate
–
per unit
Item B Unit Rate
–
per unit
What is a Unit Rate?
A unit rate is a ratio between two different units where the denominator is simplified to 1. It allows you to calculate the cost, speed, or efficiency per single unit of measurement. This is essential for comparing products of different sizes, calculating average speeds, or determining density.
How to Calculate Unit Rate
The formula for unit rate is simple arithmetic division:
Unit Rate = Total Amount รท Total Quantity
For example:
Grocery Shopping: If 12 ounces of coffee costs $15.00, the unit rate is $15.00 / 12 = $1.25 per ounce.
Travel Speed: If you drive 150 miles in 3 hours, your unit rate is 150 / 3 = 50 miles per hour.
Work Efficiency: If you type 400 words in 5 minutes, your unit rate is 400 / 5 = 80 words per minute.
Why Use a Unit Rate Calculator?
While the math is straightforward, real-world comparisons often involve awkward numbers (e.g., 14.5 oz vs 32 oz). This calculator instantly handles the division for two different scenarios, allowing you to:
Find the Better Deal: Determine which product size offers a lower price per unit.
Compare Efficiencies: Compare athletes, vehicles, or machines to see which performs better per unit of time or fuel.
Standardize Data: Convert raw data totals into comparable "per 1" metrics for analysis.
function calculateUnitRates() {
// Get Inputs
var numA = document.getElementById('numeratorA').value;
var denA = document.getElementById('denominatorA').value;
var numB = document.getElementById('numeratorB').value;
var denB = document.getElementById('denominatorB').value;
// Elements to update
var resultContainer = document.getElementById('urcResultContainer');
var rateAEl = document.getElementById('rateResultA');
var rateBEl = document.getElementById('rateResultB');
var boxA = document.getElementById('boxA');
var boxB = document.getElementById('boxB');
var mainMsg = document.getElementById('urcMainMessage');
var savingsText = document.getElementById('savingsText');
// Validation Variables
var valA = parseFloat(numA);
var qtyA = parseFloat(denA);
var valB = parseFloat(numB);
var qtyB = parseFloat(denB);
var hasA = !isNaN(valA) && !isNaN(qtyA) && qtyA !== 0;
var hasB = !isNaN(valB) && !isNaN(qtyB) && qtyB !== 0;
// Reset styling
boxA.className = "urc-result-box";
boxB.className = "urc-result-box";
savingsText.innerHTML = "";
if (!hasA && !hasB) {
alert("Please enter valid numbers for at least one item. The Quantity cannot be zero.");
resultContainer.style.display = 'none';
return;
}
resultContainer.style.display = 'block';
var rateA = 0;
var rateB = 0;
// Calculate A
if (hasA) {
rateA = valA / qtyA;
// Format to reasonable decimals (up to 4 if small number, 2 if larger)
rateAEl.innerText = rateA % 1 !== 0 ? rateA.toFixed(4).replace(/\.?0+$/, "") : rateA;
} else {
rateAEl.innerText = "-";
}
// Calculate B
if (hasB) {
rateB = valB / qtyB;
rateBEl.innerText = rateB % 1 !== 0 ? rateB.toFixed(4).replace(/\.?0+$/, "") : rateB;
} else {
rateBEl.innerText = "-";
}
// Logic for Comparison
if (hasA && hasB) {
if (rateA < rateB) {
mainMsg.innerText = "Item A has the lower Unit Rate";
boxA.classList.add("urc-winner");
var diff = ((rateB – rateA) / rateB) * 100;
savingsText.innerText = "Item A is approximately " + diff.toFixed(1) + "% more efficient/cheaper per unit than Item B.";
} else if (rateB < rateA) {
mainMsg.innerText = "Item B has the lower Unit Rate";
boxB.classList.add("urc-winner");
var diff = ((rateA – rateB) / rateA) * 100;
savingsText.innerText = "Item B is approximately " + diff.toFixed(1) + "% more efficient/cheaper per unit than Item A.";
} else {
mainMsg.innerText = "Both Items have the exact same Unit Rate";
savingsText.innerText = "There is no difference in value per unit.";
}
} else {
mainMsg.innerText = "Unit Rate Calculated";
savingsText.innerText = "Enter a second item to compare values.";
}
}
function resetUnitRates() {
document.getElementById('numeratorA').value = '';
document.getElementById('denominatorA').value = '';
document.getElementById('numeratorB').value = '';
document.getElementById('denominatorB').value = '';
document.getElementById('urcResultContainer').style.display = 'none';
var boxA = document.getElementById('boxA');
var boxB = document.getElementById('boxB');
boxA.className = "urc-result-box";
boxB.className = "urc-result-box";
}