Compare two items to find the best value or calculate speed/density.
Option A
Option B
Option A Unit Rate
–
per unit
Option B Unit Rate
–
per unit
Calculation Verdict:
Enter values to see the comparison.
How to Find Unit Rates
A unit rate is a ratio between two different units where the denominator is simplified to one. It is used to compare quantities of different sizes to determine which offers better value, higher speed, or greater efficiency. Whether you are grocery shopping, calculating gas mileage, or solving a physics problem, finding the unit rate is an essential skill.
The Unit Rate Formula
To find a unit rate, you divide the numerator (the top number, often the cost or distance) by the denominator (the bottom number, often the quantity or time).
Unit Rate = Quantity 1 ÷ Quantity 2
Examples of Unit Rates
Cost Per Unit: If a 32oz bottle of juice costs $4.00, the unit rate is $4.00 ÷ 32 = $0.125 per ounce.
Speed: If you drive 150 miles in 3 hours, the unit rate is 150 ÷ 3 = 50 miles per hour.
Wages: If you earn $200 for 8 hours of work, your unit rate is $200 ÷ 8 = $25 per hour.
Why Use a Unit Rate Calculator?
Comparing prices at the store can be deceptive. A bulk package looks like a better deal, but isn't always cheaper per unit. This calculator instantly performs the division for two different options, normalizing the data so you can make an apples-to-apples comparison. In physics and math, it ensures accuracy when converting complex ratios into simplified terms.
// Logic to switch labels based on mode
function updateLabels() {
var mode = document.querySelector('input[name="calcMode"]:checked').value;
var labelNumA = document.getElementById('label-num-A');
var labelDenA = document.getElementById('label-den-A');
var labelNumB = document.getElementById('label-num-B');
var labelDenB = document.getElementById('label-den-B');
var inputNumA = document.getElementById('ur-input-num-A');
var inputDenA = document.getElementById('ur-input-den-A');
var inputNumB = document.getElementById('ur-input-num-B');
var inputDenB = document.getElementById('ur-input-den-B');
if (mode === 'price') {
// Cost Mode Labels
labelNumA.innerText = "Total Price ($)";
labelDenA.innerText = "Total Quantity (oz, lbs, count)";
labelNumB.innerText = "Total Price ($)";
labelDenB.innerText = "Total Quantity (oz, lbs, count)";
// Placeholders
inputNumA.placeholder = "e.g. 15.00";
inputDenA.placeholder = "e.g. 32";
inputNumB.placeholder = "e.g. 24.50";
inputDenB.placeholder = "e.g. 64";
} else {
// General Mode Labels
labelNumA.innerText = "Quantity 1 (Distance, Work, Mass)";
labelDenA.innerText = "Quantity 2 (Time, Volume)";
labelNumB.innerText = "Quantity 1 (Distance, Work, Mass)";
labelDenB.innerText = "Quantity 2 (Time, Volume)";
// Placeholders
inputNumA.placeholder = "e.g. 100";
inputDenA.placeholder = "e.g. 2";
inputNumB.placeholder = "e.g. 250";
inputDenB.placeholder = "e.g. 4.5″;
}
}
// Main Calculation Logic
function calculateUnitRates() {
// 1. Get Values
var numA = parseFloat(document.getElementById('ur-input-num-A').value);
var denA = parseFloat(document.getElementById('ur-input-den-A').value);
var numB = parseFloat(document.getElementById('ur-input-num-B').value);
var denB = parseFloat(document.getElementById('ur-input-den-B').value);
var mode = document.querySelector('input[name="calcMode"]:checked').value;
// 2. Validate Inputs
if (isNaN(numA) || isNaN(denA) || denA === 0) {
alert("Please enter valid numbers for Option A. Denominator cannot be zero.");
return;
}
// Check if B is being used (optional, but if partial B filled, warn)
var hasB = (!isNaN(numB) && !isNaN(denB));
if (hasB && denB === 0) {
alert("Denominator for Option B cannot be zero.");
return;
}
// 3. Perform Calculations
var rateA = numA / denA;
var rateB = hasB ? (numB / denB) : 0;
// 4. Formatting Helper
function formatRate(val, isPrice) {
if (isPrice) {
return "$" + val.toFixed(4); // Show more decimals for small unit costs
}
return parseFloat(val.toFixed(4)); // Strip trailing zeros for general
}
// 5. Update UI
document.getElementById('ur-result-area').style.display = 'block';
// Display Rate A
document.getElementById('display-rate-A').innerText = formatRate(rateA, mode === 'price');
document.getElementById('sub-rate-A').innerText = (mode === 'price') ? "per unit" : "unit rate";
// Display Rate B (if exists)
if (hasB) {
document.getElementById('display-rate-B').innerText = formatRate(rateB, mode === 'price');
document.getElementById('sub-rate-B').innerText = (mode === 'price') ? "per unit" : "unit rate";
document.getElementById('card-result-B').style.opacity = "1";
} else {
document.getElementById('display-rate-B').innerText = "-";
document.getElementById('card-result-B').style.opacity = "0.5";
// Reset styles if only A calculated
document.getElementById('card-result-A').className = 'ur-result-card';
document.getElementById('card-result-B').className = 'ur-result-card';
document.getElementById('ur-verdict-text').innerHTML = "Enter Option B values to compare rates.";
return;
}
// 6. Comparison Logic
var cardA = document.getElementById('card-result-A');
var cardB = document.getElementById('card-result-B');
var verdict = document.getElementById('ur-verdict-text');
// Reset classes
cardA.className = 'ur-result-card';
cardB.className = 'ur-result-card';
if (mode === 'price') {
// Lower is better for price
if (rateA < rateB) {
cardA.classList.add('winner');
cardB.classList.add('loser');
var savings = ((rateB – rateA) / rateB) * 100;
verdict.innerHTML = "Option A is the better deal!It is approximately " + savings.toFixed(1) + "% cheaper per unit than Option B.";
} else if (rateB < rateA) {
cardB.classList.add('winner');
cardA.classList.add('loser');
var savings = ((rateA – rateB) / rateA) * 100;
verdict.innerHTML = "Option B is the better deal!It is approximately " + savings.toFixed(1) + "% cheaper per unit than Option A.";
} else {
verdict.innerHTML = "Both options have the exact same unit price.";
}
} else {
// General mode (Context dependent, usually just compare magnitude)
if (rateA > rateB) {
cardA.classList.add('winner'); // Highlighting higher rate
verdict.innerHTML = "Option A has a higher rate.";
} else if (rateB > rateA) {
cardB.classList.add('winner');
verdict.innerHTML = "Option B has a higher rate.";
} else {
verdict.innerHTML = "Both options have the same rate.";
}
}
}