A decimal to fraction calculator that handles both terminating decimals (like 0.375) and repeating decimals (like 0.142857142857…), converts them to the exact simplest fraction in lowest terms, and shows every step of the working. The result is displayed as an improper fraction, a mixed number where applicable, and a decimal round-trip verification. For denominators up to 24 a shaded bar diagram gives a visual sense of the proportion.
How it works
Terminating decimals — the continued-fraction method
For a terminating decimal the calculator uses the continued-fraction (CF) algorithm:
- Separate the whole-number part from the fractional part.
- Apply the CF expansion to the fractional part: at each step take
a = floor(b), update the convergent numeratorhand denominatorkusing the recurrenceh(i) = a * h(i-1) + h(i-2), stop whenkexceeds 1,000,000 or the remainder is exactly zero. - Reduce the result with
GCD(numerator, denominator).
This is more numerically stable than the naive “multiply by a power of ten” method, because floating-point arithmetic can introduce a spurious 9 or 0 at the end of a decimal representation.
Repeating decimals — the algebraic shortcut
For a repeating decimal 0.nonRepeat(repeat) the formula is:
numerator = (nonRepeat + repeat) as integer − (nonRepeat) as integer
denominator = 10^len(nonRepeat) × (10^len(repeat) − 1)
For example, 0.3(142857) gives numerator = 3142857 − 3 = 3142854 and denominator
= 10 × 999999 = 9999990. Dividing both by GCD(3142854, 9999990) = 285714 yields
3142854 / 9999990 = 11/35.
A simpler example: 0.(3) gives numerator = 3 − 0 = 3, denominator = 1 × 9 = 9,
which simplifies to 1/3. This is the clean algebraic proof that 0.333… = 1/3.
Worked example — terminating decimal
Convert 1.625:
- Whole part = 1, fractional part = 0.625.
- CF expansion of 0.625:
a=0, nextb = 1/(0.625−0) = 1.6,a=1, etc. — convergents approach 5/8. - Combine:
1 + 5/8 = 8/8 + 5/8 = 13/8. - GCD(13, 8) = 1, so lowest terms = 13/8 (or mixed: 1 5/8).
Worked example — repeating decimal
Convert 0.142857142857… (the repeating expansion of 1/7):
- Non-repeating digits after decimal: none (leave blank)
- Repeating block:
142857
Formula: numerator = 142857 − 0 = 142857, denominator = 1 × (10^6 − 1) = 999999.
GCD(142857, 999999) = 142857, so 142857/999999 = 1/7.
| Decimal | Fraction | Form |
|---|---|---|
| 0.5 | 1/2 | terminating |
| 0.375 | 3/8 | terminating |
| 1.625 | 13/8 | terminating |
| 0.333… | 1/3 | repeating, block “3” |
| 0.666… | 2/3 | repeating, block “6” |
| 0.142857… | 1/7 | repeating, block “142857” |
Formula note
The GCD used throughout is computed by Euclid’s algorithm:
GCD(a, b) = GCD(b, a mod b) until b = 0, then a is the answer.
The LCM (used in some fraction-arithmetic contexts) is LCM(a, b) = (a / GCD(a,b)) * b.
All arithmetic stays within JavaScript’s safe integer range (up to 2^53 − 1) for any
realistic decimal input.
Everything runs in your browser — no numbers are uploaded or stored anywhere.