Enter fractions and select an operation to see the step-by-step calculation.
Understanding and Using the Fraction Calculator
Fractions represent a part of a whole. They are written as two numbers separated by a line (e.g., 1⁄2), where the top number is the numerator and the bottom number is the denominator.
How the Operations Work:
1. Addition (a/b + c/d)
Find a Common Denominator: The simplest way is to multiply the denominators: b * d.
Adjust Numerators: Multiply the first numerator (a) by the second denominator (d), and the second numerator (c) by the first denominator (b).
Add the Adjusted Numerators: The new numerator is (a * d) + (c * b). The denominator remains b * d.
Result:(ad + cb) / bd
Simplification: Find the Greatest Common Divisor (GCD) of the new numerator and denominator, and divide both by it.
2. Subtraction (a/b – c/d)
Find a Common Denominator: Multiply the denominators: b * d.
Adjust Numerators: Multiply the first numerator (a) by the second denominator (d), and the second numerator (c) by the first denominator (b).
Subtract the Adjusted Numerators: The new numerator is (a * d) - (c * b). The denominator remains b * d.
Result:(ad - cb) / bd
Simplification: Find the GCD of the new numerator and denominator, and divide both by it.
3. Multiplication (a/b * c/d)
Multiply Numerators:a * c.
Multiply Denominators:b * d.
Result:(a * c) / (b * d)
Simplification: Find the GCD of the resulting numerator and denominator, and divide both by it.
4. Division (a/b / c/d)
Invert the Second Fraction: Turn c/d into its reciprocal d/c.
Multiply: Multiply the first fraction by the inverted second fraction: a/b * d/c.
Result:(a * d) / (b * c)
Simplification: Find the GCD of the resulting numerator and denominator, and divide both by it.
Simplifying Fractions (GCD)
To simplify a fraction, you find the Greatest Common Divisor (GCD) – the largest number that divides both the numerator and the denominator without leaving a remainder. Then, you divide both the numerator and the denominator by the GCD.
Use Cases
Mathematics Education: Helps students understand fraction arithmetic visually and step-by-step.
Cooking and Baking: Easily adjust recipes that use fractional measurements.
Engineering and Design: Performing calculations involving precise measurements.
Everyday Problem Solving: Dividing items, calculating proportions, etc.
// Helper function to calculate the Greatest Common Divisor (GCD) using the Euclidean algorithm
var gcd = function(a, b) {
var absA = Math.abs(a);
var absB = Math.abs(b);
while (absB) {
var temp = absB;
absB = absA % absB;
absA = temp;
}
return absA;
};
// Helper function to simplify a fraction
var simplifyFraction = function(numerator, denominator) {
if (denominator === 0) {
return { num: NaN, den: NaN, error: "Division by zero in denominator." };
}
if (numerator === 0) {
return { num: 0, den: 1, simplifiedSteps: "Numerator is 0, so the fraction is 0." };
}
var commonDivisor = gcd(numerator, denominator);
var simplifiedNumerator = Math.round(numerator / commonDivisor); // Use Math.round to handle potential floating point inaccuracies with large numbers
var simplifiedDenominator = Math.round(denominator / commonDivisor);
// Ensure the denominator is positive
if (simplifiedDenominator < 0) {
simplifiedNumerator = -simplifiedNumerator;
simplifiedDenominator = -simplifiedDenominator;
}
var steps = "";
if (numerator !== simplifiedNumerator || denominator !== simplifiedDenominator) {
steps = `Simplifying ${numerator}/${denominator}: GCD is ${commonDivisor}. Result: ${simplifiedNumerator}/${simplifiedDenominator}.`;
} else {
steps = `Fraction ${numerator}/${denominator} is already in its simplest form.`;
}
return { num: simplifiedNumerator, den: simplifiedDenominator, simplifiedSteps: steps };
};
var calculateFraction = function() {
var n1 = parseFloat(document.getElementById("numerator1").value);
var d1 = parseFloat(document.getElementById("denominator1").value);
var n2 = parseFloat(document.getElementById("numerator2").value);
var d2 = parseFloat(document.getElementById("denominator2").value);
var operation = document.getElementById("operation").value;
var resultDiv = document.getElementById("result");
var htmlOutput = "";
// Input validation
if (isNaN(n1) || isNaN(d1) || isNaN(n2) || isNaN(d2)) {
resultDiv.innerHTML = "Please enter valid numbers for all fraction parts.";
return;
}
if (d1 === 0 || d2 === 0) {
resultDiv.innerHTML = "Denominators cannot be zero.";
return;
}
var resultNum, resultDen;
var steps = "";
var fraction1Str = `${n1}/${d1}`;
var fraction2Str = `${n2}/${d2}`;
if (operation === "add") {
steps += `
Addition: ${fraction1Str} + ${fraction2Str}
`;
var commonDenominator = d1 * d2;
var adjustedN1 = n1 * d2;
var adjustedN2 = n2 * d1;
resultNum = adjustedN1 + adjustedN2;
resultDen = commonDenominator;
steps += `1. Find a common denominator: ${d1} * ${d2} = ${commonDenominator}.`;
steps += `2. Adjust numerators: (${n1} * ${d2}) + (${n2} * ${d1}) = ${adjustedN1} + ${adjustedN2} = ${resultNum}.`;
steps += `3. Combine: The result is ${resultNum}/${resultDen}.`;
} else if (operation === "subtract") {
steps += `
Subtraction: ${fraction1Str} – ${fraction2Str}
`;
var commonDenominator = d1 * d2;
var adjustedN1 = n1 * d2;
var adjustedN2 = n2 * d1;
resultNum = adjustedN1 – adjustedN2;
resultDen = commonDenominator;
steps += `1. Find a common denominator: ${d1} * ${d2} = ${commonDenominator}.`;
steps += `2. Adjust numerators: (${n1} * ${d2}) – (${n2} * ${d1}) = ${adjustedN1} – ${adjustedN2} = ${resultNum}.`;
steps += `3. Combine: The result is ${resultNum}/${resultDen}.`;
} else if (operation === "multiply") {
steps += `