Divide two fractions and get the simplified result with step-by-step instructions.
÷
=
?
Result & Steps
How to Divide Fractions: The Keep-Change-Flip Method
Dividing fractions might seem complex, but it follows a simple three-step rule often called Keep, Change, Flip (KCF). This method converts a division problem into a simple multiplication problem.
Keep: Leave the first fraction exactly as it is.
Change: Change the division sign (÷) to a multiplication sign (×).
Flip: Turn the second fraction upside down (this is called finding the reciprocal). The numerator becomes the denominator, and the denominator becomes the numerator.
After multiplying the numerators and denominators, you often end up with a large fraction. To simplify, find the Greatest Common Divisor (GCD) of both the top and bottom numbers and divide both by that number. Our calculator does this automatically for you!
Why Can't the Denominator Be Zero?
In mathematics, division by zero is undefined. A fraction represents a part of a whole; if the whole (denominator) is zero, the fraction cannot exist. Ensure both denominators in your calculation are non-zero numbers.
function gcd(a, b) {
a = Math.abs(a);
b = Math.abs(b);
while (b) {
var t = b;
b = a % b;
a = t;
}
return a;
}
function calculateFractions() {
var n1 = parseInt(document.getElementById('num1').value);
var d1 = parseInt(document.getElementById('den1').value);
var n2 = parseInt(document.getElementById('num2').value);
var d2 = parseInt(document.getElementById('den2').value);
var resultDiv = document.getElementById('fd-result');
var stepsDiv = document.getElementById('fd-steps-content');
var finalDiv = document.getElementById('fd-final-display');
// Validation
if (isNaN(n1) || isNaN(d1) || isNaN(n2) || isNaN(d2)) {
alert("Please fill in all four fields with valid numbers.");
return;
}
if (d1 === 0 || d2 === 0) {
alert("Denominator cannot be zero.");
return;
}
if (n2 === 0) {
alert("To divide by a fraction, its numerator cannot be zero because flipping it would result in division by zero.");
return;
}
// Logic: (n1/d1) / (n2/d2) = (n1/d1) * (d2/n2)
var finalNum = n1 * d2;
var finalDen = d1 * n2;
// Simplify
var commonDivisor = gcd(finalNum, finalDen);
var simplifiedNum = finalNum / commonDivisor;
var simplifiedDen = finalDen / commonDivisor;
// Handle negative signs for display
if (simplifiedDen < 0) {
simplifiedNum = -simplifiedNum;
simplifiedDen = -simplifiedDen;
}
// Generate Steps HTML
var stepsHtml = "Step 1: Keep the first fraction: " + n1 + "/" + d1 + "";
stepsHtml += "Step 2: Change division to multiplication (×).";
stepsHtml += "Step 3: Flip the second fraction (" + n2 + "/" + d2 + ") to its reciprocal: " + d2 + "/" + n2 + ".";
stepsHtml += "Step 4: Multiply the numerators and denominators: (" + n1 + " × " + d2 + ") / (" + d1 + " × " + n2 + ") = " + finalNum + "/" + finalDen + ".";
if (commonDivisor > 1) {
stepsHtml += "Step 5: Simplify by dividing both parts by " + commonDivisor + ".";
} else {
stepsHtml += "Step 5: The fraction is already in its simplest form.";
}
stepsDiv.innerHTML = stepsHtml;
// Final Display Logic
var finalOutput = "Final Answer: ";
if (simplifiedDen === 1) {
finalOutput += simplifiedNum;
} else {
finalOutput += simplifiedNum + "/" + simplifiedDen;
}
// Mixed number conversion if improper
if (Math.abs(simplifiedNum) > Math.abs(simplifiedDen) && simplifiedDen !== 1) {
var whole = Math.floor(Math.abs(simplifiedNum) / simplifiedDen);
var rem = Math.abs(simplifiedNum) % simplifiedDen;
var sign = simplifiedNum < 0 ? "-" : "";
finalOutput += " (or " + sign + whole + " " + rem + "/" + simplifiedDen + ")";
}
finalDiv.innerHTML = finalOutput;
resultDiv.style.display = "block";
document.getElementById('quick-result-preview').innerText = (simplifiedDen === 1) ? simplifiedNum : (simplifiedNum + "/" + simplifiedDen);
}