Use '…' or '*' to indicate the repeating part. For non-repeating part, do not use '…'. Example: 0.123454545… should be entered as 0.12…45 or 0.12*45.
Your fraction will appear here.
Understanding Repeating Decimals and Their Fraction Conversion
Repeating decimals are decimal numbers where a sequence of digits repeats infinitely after the decimal point. These can be expressed as exact fractions. For example, 0.333… is famously equal to 1/3, and 0.142857142857… is equal to 1/7. Converting these repeating decimals into their fractional form is a fundamental concept in mathematics, useful in various scientific and engineering fields.
Types of Repeating Decimals
Purely Repeating Decimals: The repeating sequence starts immediately after the decimal point. Example: 0.121212… (repeating block is '12').
Mixed Repeating Decimals: There is a non-repeating part before the repeating part begins. Example: 0.123454545… (non-repeating part is '123', repeating block is '45').
The Mathematical Process
The conversion relies on algebraic manipulation. Let's break down the process:
1. Purely Repeating Decimals (e.g., 0.121212…)
Let x equal the decimal: x = 0.121212...
Determine the number of repeating digits. Here, it's 2 ('12').
Multiply x by 10 raised to the power of the number of repeating digits (102 = 100): 100x = 12.121212...
Subtract the original equation (x = 0.121212...) from the multiplied equation:
100x - x = 12.121212... - 0.121212... 99x = 12
Solve for x: x = 12/99
Simplify the fraction: x = 4/33
2. Mixed Repeating Decimals (e.g., 0.123454545…)
Let x equal the decimal: x = 0.123454545...
Identify the non-repeating part ('123′) and the repeating part ('45').
Multiply x by 10 raised to the power of the number of digits in the non-repeating part (3 digits: '1', '2', '3'). So, multiply by 103 = 1000:
1000x = 123.454545...
Now, we need to isolate the repeating part. Multiply x by 10 raised to the power of the total number of digits before the repeating part ends (non-repeating digits + one cycle of repeating digits). Here, that's 3 (non-repeating) + 2 (repeating) = 5 digits. So, multiply by 105 = 100000:
100000x = 12345.454545...
Subtract the equation from step 3 from the equation in step 4:
100000x - 1000x = 12345.454545... - 123.454545... 99000x = 12222
Solve for x: x = 12222/99000
Simplify the fraction. Both numerator and denominator are divisible by 6:
x = 2037/16500. This can be further simplified. Both are divisible by 3:
x = 679/5500.
How This Calculator Works
This calculator automates the process described above. It parses your input, identifies the non-repeating and repeating parts of the decimal, and applies the algebraic rules to generate the equivalent fraction. It then simplifies the fraction to its lowest terms using the Greatest Common Divisor (GCD) algorithm.
Use Cases
Mathematics Education: Helps students visualize and understand the relationship between decimals and fractions.
Scientific Calculations: Ensures precision when dealing with numbers that have repeating decimal representations.
Programming: Useful for developing algorithms that require exact numerical representations.
// Function to find the Greatest Common Divisor (GCD)
function gcd(a, b) {
var a = Math.abs(a);
var b = Math.abs(b);
while(b) {
var t = b;
b = a % b;
a = t;
}
return a;
}
// Function to convert a repeating decimal string to a fraction
function convertToFraction() {
var decimalString = document.getElementById("decimalInput").value.trim();
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = 'Your fraction will appear here.'; // Reset result
if (!decimalString) {
resultDiv.innerHTML = 'Please enter a decimal number.';
return;
}
var nonRepeatingPart = "";
var repeatingPart = "";
var integerPart = "0";
var decimalPointIndex = decimalString.indexOf('.');
if (decimalPointIndex === -1) {
// It's an integer, which is already a fraction (e.g., 5 = 5/1)
resultDiv.innerHTML = " + decimalString + '/1';
return;
}
integerPart = decimalString.substring(0, decimalPointIndex);
var decimalPartString = decimalString.substring(decimalPointIndex + 1);
var repeatingIndicatorIndex = -1;
if (decimalPartString.includes("…")) {
repeatingIndicatorIndex = decimalPartString.indexOf("…");
} else if (decimalPartString.includes("*")) {
repeatingIndicatorIndex = decimalPartString.indexOf("*");
}
if (repeatingIndicatorIndex === -1) {
// No repeating part indicated, assume it's a terminating decimal
// Treat as a simple fraction
try {
var num = parseFloat(decimalString);
if (isNaN(num)) throw new Error("Invalid number format.");
var fraction = num.toString().split('.');
var denominator = Math.pow(10, fraction[1].length);
var numerator = parseInt(fraction[0] + fraction[1]);
var commonDivisor = gcd(numerator, denominator);
var simplifiedNumerator = numerator / commonDivisor;
var simplifiedDenominator = denominator / commonDivisor;
// Add integer part back if present
var finalNumerator = simplifiedNumerator + parseInt(integerPart) * simplifiedDenominator;
var finalDenominator = simplifiedDenominator;
var commonDivisorFinal = gcd(finalNumerator, finalDenominator);
simplifiedNumerator = finalNumerator / commonDivisorFinal;
simplifiedDenominator = finalDenominator / commonDivisorFinal;
resultDiv.innerHTML = " + simplifiedNumerator + '/' + simplifiedDenominator + ";
} catch (e) {
resultDiv.innerHTML = 'Invalid decimal format. Please use a valid number or indicate repeating part with "…" or "*".';
}
return;
}
// Handle repeating decimals
nonRepeatingPart = decimalPartString.substring(0, repeatingIndicatorIndex);
repeatingPart = decimalPartString.substring(repeatingIndicatorIndex + 3); // +3 to skip '…' or '*' and potential space
if (!repeatingPart) {
resultDiv.innerHTML = 'Repeating part cannot be empty.';
return;
}
try {
var numNonRepeating = parseInt(nonRepeatingPart || "0");
var numRepeating = parseInt(repeatingPart);
var lenNonRepeating = nonRepeatingPart.length;
var lenRepeating = repeatingPart.length;
var numerator;
var denominator;
// Formula for mixed repeating decimals:
// N = (Number formed by non-repeating + repeating digits) – (Number formed by non-repeating digits)
// D = (10^len_repeating – 1) followed by (10^len_non_repeating zeroes)
var numeratorPart1 = parseInt(nonRepeatingPart + repeatingPart) || 0;
var numeratorPart2 = parseInt(nonRepeatingPart || "0");
numerator = numeratorPart1 – numeratorPart2;
var denominatorStr = '9'.repeat(lenRepeating) + '0'.repeat(lenNonRepeating);
denominator = parseInt(denominatorStr);
// Handle case where non-repeating part is empty (purely repeating)
if (lenNonRepeating === 0) {
numerator = numRepeating;
denominator = parseInt('9'.repeat(lenRepeating));
}
// Add integer part
var totalNumerator = numerator + (parseInt(integerPart) * denominator);
var totalDenominator = denominator;
// Simplify the fraction
var commonDivisor = gcd(totalNumerator, totalDenominator);
var simplifiedNumerator = totalNumerator / commonDivisor;
var simplifiedDenominator = totalDenominator / commonDivisor;
resultDiv.innerHTML = " + simplifiedNumerator + '/' + simplifiedDenominator + ";
} catch (e) {
console.error("Calculation error:", e);
resultDiv.innerHTML = 'Invalid input format. Ensure numbers are entered correctly.';
}
}
// Function to clear inputs and reset result
function clearInputs() {
document.getElementById("decimalInput").value = "";
document.getElementById("result").innerHTML = 'Your fraction will appear here.';
}
// Add event listener for Enter key on the input field
document.getElementById("decimalInput").addEventListener("keypress", function(event) {
if (event.key === "Enter") {
event.preventDefault(); // Prevent default form submission
convertToFraction();
}
});