Fractions, Decimals and Continued Fractions
After reading this you can turn any fraction into its exact decimal (repeating part included), turn a decimal back into the cleanest fraction that produces it, and read a continued fraction to find the best rational approximations of a number.
Three notations describe the same rational numbers, and each one hides information the others show. The fraction 355/113 tells you the exact ratio but not how big it is. Its decimal 3.1415929... tells you the size but buries the ratio. Its continued fraction [3; 7, 16] tells you almost nothing at a glance, yet it reveals that 355/113 is one of the sharpest approximations of \pi that any small denominator can give.
This guide explains all three forms and how to move between them by hand, so you can check what the calculator produces.
What each form is good for
A fraction is exact and compact. A decimal is easy to compare and to feed into other arithmetic. A continued fraction ranks the simple approximations of a number from crudest to finest.
- Fraction
- A ratio p/q of two integers with q \ne 0. In lowest terms, \gcd(p, q) = 1.
- Terminating decimal
- A decimal that stops, such as
0.375. This happens exactly when the reduced denominator has no prime factors except 2 and 5. - Repeating decimal
- A decimal with a block that repeats forever, written with an overline, such as
0.\overline{142857}for1/7. - Continued fraction
- A number written as a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cdots}}, recorded compactly as [a_0; a_1, a_2, \ldots].
When to use it and when not
Use this converter when you need an exact answer. If you divide 1 by 7 on a phone you get 0.14285714, which drops the pattern and rounds the last digit. The exact form 0.\overline{142857} keeps every digit.
Reach for the continued fraction when you want to replace an awkward number with a simple fraction and control the error. If you need a gear ratio close to \pi but must keep teeth counts small, 22/7 and 355/113 come straight out of the expansion.
A decimal you type is a finite string, so the calculator matches it exactly as a rational number. Typing 0.333 gives 333/1000, not 1/3. If you mean the repeating value, enter the fraction, or type enough digits and read off the convergent that the calculator suggests.
Fraction to decimal by long division
Divide p by q and watch the remainders. Each step multiplies the current remainder by 10 and divides again. There are only q possible nonzero remainders, so a remainder must eventually repeat, and from that point the digits repeat too.
Here a_0 is the integer part and each d_i is a decimal digit produced by the running remainder. The decimal terminates only if some remainder hits 0. That can happen only when q (after reducing) is built from the primes 2 and 5, because those are the prime factors of 10.
Take 3/7, the default value. The remainders run 3, 2, 6, 4, 5, 1 and then back to 3, giving the digits 428571 before the cycle restarts. So 3/7 = 0.\overline{428571}, a repeating block of length 6.
Decimal to fraction
A terminating decimal converts by placing the digits over the right power of 10 and reducing. For 0.375 you write 375/1000, then divide top and bottom by \gcd(375, 1000) = 125 to get 3/8.
A known repeating decimal converts with a subtraction trick. Let x = 0.\overline{142857}. The block has 6 digits, so multiply by 10^6:
The denominator 999999 is six 9s, one for each repeating digit. Reducing by \gcd(142857, 999999) = 142857 gives 1/7.
Continued fractions and convergents
To build a continued fraction, take the integer part, subtract it, invert the remainder, and repeat. Each integer part becomes a term a_i.
Every finite continued fraction is a rational number, and every rational number has a finite expansion. Cutting the expansion off after a few terms gives a convergent: a fraction p_k/q_k. Convergents are the best rational approximations in a strict sense: no fraction with a denominator up to q_k is closer to x.
You build them with a recurrence. Starting from p_{-1}=1, p_{-2}=0, q_{-1}=0, q_{-2}=1:
Consecutive convergents straddle the target, alternating above and below, and the gap shrinks fast when a term a_k is large.
A large term signals an unusually good approximation just before it. In \pi = [3; 7, 15, 1, 292, \ldots], the 292 is why 355/113 is so accurate: the next improvement waits a long time.
Reproducing the demo: 355/113
Set mode to Fraction → decimal and value to 355/113.
- Divide:
355 ÷ 113 = 3with remainder16, so the integer part is3and a_0 = 3. - The decimal is
3.1415929203539823...and repeats with a period of 112 digits, since 113 is prime and coprime to 10. - For the continued fraction, invert
113/16 = 7.0625, giving a_1 = 7. Then16/1 = 16, giving a_2 = 16. So355/113 = [3; 7, 16]. - Convergents: p_0/q_0 = 3/1, then p_1/q_1 = (7\cdot3+1)/(7\cdot1+0) = 22/7, then p_2/q_2 = (16\cdot22+3)/(16\cdot7+1) = 355/113.
Compared with \pi, the convergent 22/7 = 3.142857 is off by about 0.00126, while 355/113 = 3.141593 is off by only about 0.000000267.
Reading the calculator output
For a fraction to decimal conversion you get the reduced fraction, the integer part, the non-repeating prefix, and the repeating block if there is one. A period of length 1 like 1/3 = 0.\overline{3} is common; a period as long as q-1 happens when 10 is a primitive root mod q, as with 1/7 (period 6) and 1/17 (period 16).
For a decimal to fraction conversion you get the exact fraction for what you typed, plus a table of convergents up to the denominator limit. Scan that table: often a nearby simple fraction is what you actually meant.
| Fraction | Decimal | Period length |
|---|---|---|
| 1/2 | 0.5 | 0 (terminates) |
| 1/3 | 0.\overline{3} | 1 |
| 1/7 | 0.\overline{142857} | 6 |
| 1/11 | 0.\overline{09} | 2 |
| 1/13 | 0.\overline{076923} | 6 |
Common mistakes
The first mistake is confusing a typed decimal with a repeating one. As noted above, 0.142857 is 142857/1000000, not 1/7. Only the exact repeating form gives 1/7.
The second is rounding before converting. If you round \pi to 3.14 and convert, you get 157/50, not a convergent of \pi. Feed as many true digits as you have.
The third is ignoring the denominator limit. If Largest allowed denominator is set to 10000, the calculator stops at the last convergent with q \le 10000. Raise it if you need finer approximations.
Related tools
To factor a denominator and see why a decimal terminates or repeats, use the Prime factorization and number theory calculator; a denominator with only 2s and 5s terminates. To write the same value in another base, try the number base converter. When numerators and denominators grow past normal precision, the big number calculator keeps every digit exact. For rounding a decimal to a fixed number of significant figures, see scientific notation and significant figures.
Frequently asked questions
Why does 1/7 repeat but 1/8 does not?
Because 8 = 2^3 uses only the prime 2, which divides 10, so the division ends: 1/8 = 0.125. Since 7 shares no factor with 10, no remainder ever reaches 0, so the digits cycle. The cycle length for 1/7 is 6.
How accurate is a convergent?
A convergent p_k/q_k satisfies |x - p_k/q_k| \lt 1/(q_k q_{k+1}). For 355/113 the next denominator is large, so the error is under 1/(113 \cdot 33102) \approx 2.7 \times 10^{-7}, matching the observed 0.000000267.
Can every decimal be written as a fraction?
Every terminating or repeating decimal is rational and has a fraction. Non-repeating infinite decimals like \sqrt{2} are irrational and have no exact fraction, though their continued fractions still give excellent approximations.
What does the semicolon in [3; 7, 16] mean?
The semicolon separates the integer part from the fractional terms. So [3; 7, 16] means 3 + \cfrac{1}{7 + \cfrac{1}{16}}, which equals 355/113.
Why is the period of 1/113 so long?
The period equals the multiplicative order of 10 modulo the denominator. For 113 that order is 112, the largest possible, so 1/113 repeats with a 112-digit block.