Simplify ratios, calculate unit prices, and solve proportions.
1. Unit Rate Calculator
Find the price per item or rate per single unit.
2. Ratio Simplifier
Reduce a ratio to its simplest form (e.g., 10:20 to 1:2).
:
3. Proportion Solver (Missing Value)
Solve for X in the proportion A / B = C / X.
=
X
Understanding Ratios and Unit Rates
Ratios are mathematical expressions that compare two quantities of the same kind to show how many times one value is contained within the other. A unit rate is a specific type of ratio where the second quantity is reduced to 1.
How to Calculate a Unit Rate
To find a unit rate, you divide the first quantity by the second quantity. This is extremely useful for grocery shopping (price per ounce) or travel (miles per hour).
Formula: Unit Rate = Total Amount / Total Quantity
Real-World Examples
Grocery Shopping: If a 20oz box of cereal costs $5.00, the unit rate is $0.25 per ounce ($5.00 ÷ 20).
Driving Speed: If you travel 120 miles in 2 hours, your unit rate is 60 miles per hour (120 ÷ 2).
Cooking: If a recipe calls for 4 cups of flour for every 2 cups of sugar, the ratio is 4:2, which simplifies to 2:1.
Solving Proportions
A proportion is an equation that states two ratios are equal. You can solve for a missing value (X) using cross-multiplication. For A/B = C/X, the formula for X is (B * C) / A.
function calculateUnitRate() {
var amount = parseFloat(document.getElementById('totalAmount').value);
var qty = parseFloat(document.getElementById('totalQuantity').value);
var resultDiv = document.getElementById('unitRateResult');
if (isNaN(amount) || isNaN(qty) || qty === 0) {
resultDiv.style.display = 'block';
resultDiv.style.color = '#c0392b';
resultDiv.innerHTML = 'Please enter valid numbers. Quantity cannot be zero.';
return;
}
var rate = amount / qty;
resultDiv.style.display = 'block';
resultDiv.style.color = '#333';
resultDiv.innerHTML = 'The Unit Rate is: ' + rate.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 4}) + ' per unit.';
}
function simplifyRatio() {
var a = Math.abs(parseInt(document.getElementById('ratioA').value));
var b = Math.abs(parseInt(document.getElementById('ratioB').value));
var resultDiv = document.getElementById('simplifyResult');
if (isNaN(a) || isNaN(b) || a === 0 || b === 0) {
resultDiv.style.display = 'block';
resultDiv.style.color = '#c0392b';
resultDiv.innerHTML = 'Please enter non-zero integers.';
return;
}
var commonFactor = function(x, y) {
while (y) {
var t = y;
y = x % y;
x = t;
}
return x;
};
var gcd = commonFactor(a, b);
resultDiv.style.display = 'block';
resultDiv.style.color = '#333';
resultDiv.innerHTML = 'Simplified Ratio: ' + (a / gcd) + ' : ' + (b / gcd);
}
function solveProportion() {
var a = parseFloat(document.getElementById('propA').value);
var b = parseFloat(document.getElementById('propB').value);
var c = parseFloat(document.getElementById('propC').value);
var resultDiv = document.getElementById('proportionResult');
if (isNaN(a) || isNaN(b) || isNaN(c) || a === 0) {
resultDiv.style.display = 'block';
resultDiv.style.color = '#c0392b';
resultDiv.innerHTML = 'Please enter valid numbers. Value A cannot be zero.';
return;
}
// Formula: A/B = C/X => X = (B * C) / A
var x = (b * c) / a;
resultDiv.style.display = 'block';
resultDiv.style.color = '#333';
resultDiv.innerHTML = 'Result: X = ' + x.toLocaleString(undefined, {maximumFractionDigits: 4});
}