Continued Fraction Calculator
- Peel off the integer parts one at a time: 3.14159 expands to the terms 3; 7; 15; 1.
- The convergents are 3/1, 22/7, 333/106, 355/113 — each is the best rational approximation with a denominator that size or smaller.
- The second convergent is 22/7 = 3.14286; the final one is 355/113 = 3.14159.
- Error against the number you entered: 2.70e-07.
A continued fraction writes a number as an integer plus a reciprocal chain, x = a0 + 1/(a1 + 1/(a2 + ...)), recorded by its terms [a0; a1, a2, ...]. This continued fraction calculator expands any number you enter into that term list and computes the convergents you get by truncating the chain. Those convergents are the best rational approximations to x with denominators of their size. Enter pi to eight decimals (3.14159265), for example, and the calculator returns the terms 3; 7; 15; 1 and the convergents 3/1, 22/7, 333/106 and 355/113. The last convergent, 355/113 = 3.14159, is in error by only 2.70e-07. The square root of 2 (1.41421356) expands to 1; 2; 2; 2; 2, and five terms give the convergent 41/29 = 1.41379, in error by 4.20e-04. The number e (2.71828183) expands to 2; 1; 2; 1; 1 in five terms, ending at the convergent 19/7 = 2.71429, in error by 4.00e-03.
Continued fractions are the accepted standard for finding optimal rational approximations because no other method produces fractions that match a target number as closely for a given denominator size. Irrational numbers have infinite expansions while rational numbers terminate, and a periodic expansion corresponds exactly to a quadratic irrational, as root 2's repeating 2s show. The convergent 355/113 was known to the Chinese mathematician Zu Chongzhi in the 5th century and stayed the most accurate rational approximation of pi for nearly a thousand years. This page shows the formula, step-by-step workings, worked examples and sources so you can verify every result the calculator produces.
Worked examples
Pi and the 355/113 convergent
Primary result: 3.14159 — the expansion 3; 7; 15; 1 ends at 355/113, accurate to 2.70e-07. (3.14159265 · 4)
| Last convergent (decimal) | 3.14159 |
| Last convergent (fraction) | 355/113 |
| Continued fraction terms | 3; 7; 15; 1 |
| Approximation error | 2.70e-07 |
Root two's endless twos
Primary result: 1.41379 — five terms of 1; 2; 2; 2; 2 give 41/29. (1.41421356 · 5)
| Last convergent (decimal) | 1.41379 |
| Last convergent (fraction) | 41/29 |
| Continued fraction terms | 1; 2; 2; 2; 2 |
| Approximation error | 4.20e-04 |
e in five terms
Primary result: 2.71429 — the pattern 2; 1; 2; 1; 1 lands on 19/7. (2.71828183 · 5)
| Last convergent (decimal) | 2.71429 |
| Last convergent (fraction) | 19/7 |
| Continued fraction terms | 2; 1; 2; 1; 1 |
| Approximation error | 4.00e-03 |
A different way to write a number
A continued fraction writes a number as an integer plus a reciprocal chain: x = a0 + 1/(a1 + 1/(a2 + ...)). Rather than listing digits, the expansion records a short list of terms [a0; a1, a2, ...]. Irrational numbers have infinite expansions, while rational numbers terminate. Truncating the chain at any point gives the convergents, which are the best rational approximations to x with denominators of their size.
This is why the terms of pi are more informative than its digits. Verified to eight decimals (3.14159265), pi expands to just four terms: 3; 7; 15; 1. The convergents are 3/1, 22/7, 333/106, and 355/113. The last convergent, 355/113 = 3.14159, is in error by only 2.70e-07. The convergent 355/113 was known to the Chinese mathematician Zu Chongzhi in the 5th century and stayed the most accurate rational approximation of pi for nearly a thousand years. Four terms of a continued fraction convey more useful information about pi than many digits ever could.
Other constants reveal their structure just as clearly. The square root of 2 (1.41421356) expands to 1; 2; 2; 2; 2 — the endless run of 2s is the signature of a quadratic irrational. Five terms give the convergent 41/29 = 1.41379, in error by 4.20e-04. A periodic expansion corresponds exactly to a quadratic irrational, as root 2's repeating 2s show. The constant e (2.71828183) expands to 2; 1; 2; 1; 1 in five terms, ending at the convergent 19/7 = 2.71429, in error by 4.00e-03.
A continued fraction calculator lets you explore these chains directly. Enter a value, and the tool returns the terms and convergents, showing how each truncation tightens the approximation. Because convergents are the best rational approximations for their denominator size, the output often reveals structure that decimal digits hide.
How the expansion is built
A continued fraction writes a number as an integer plus a reciprocal chain: x = a0 + 1/(a1 + 1/(a2 + ...)), recorded by its terms [a0; a1, a2, ...]. The expansion is built with the peel-and-invert algorithm. Start with your number x. Take the integer part as a0 and subtract it, leaving a remainder between 0 and 1. Invert that remainder, take the integer part of the result as a1, subtract, and invert again. Repeat until the remainder is zero. Irrational numbers have infinite expansions; rational numbers terminate. A periodic expansion corresponds exactly to a quadratic irrational, as the square root of 2 shows: 1.41421356 expands to 1; 2; 2; 2; 2, and the endless run of 2s is the signature of a quadratic irrational.
Truncating the chain at any point gives a convergent, and the convergents are the best rational approximations to x with denominators of their size. A continued fraction calculator computes these convergents with a recurrence relation. Given the terms a0, a1, a2, and so on, each numerator and denominator builds on the two previous pairs: the next numerator is the current term times the previous numerator plus the numerator before that, and the next denominator follows the same pattern with the previous denominators. This recurrence turns the raw terms into the fractions that approximate the original number with remarkable efficiency.
Walk through pi to eight decimals, 3.14159265. The peel-and-invert algorithm produces the terms 3; 7; 15; 1. The first convergent is simply 3/1. Applying the recurrence, the next convergent is 22/7, then 333/106, and finally 355/113. The last convergent, 355/113 = 3.14159, is in error by only 2.70e-07. This convergent was known to the Chinese mathematician Zu Chongzhi in the 5th century and stayed the most accurate rational approximation of pi for nearly a thousand years. The same method applied to e, 2.71828183, expands to 2; 1; 2; 1; 1 in five terms, ending at the convergent 19/7 = 2.71429, in error by 4.00e-03. For the square root of 2, five terms give the convergent 41/29 = 1.41379, in error by 4.20e-04.
Worked examples
The table below collects three verified expansions you can reproduce in any continued fraction calculator. Each row shows the input value, the term list [a0; a1, a2, ...] that defines the expansion, the convergent reached at the listed depth, and the absolute error of that convergent against the true value. A continued fraction writes a number as an integer plus a reciprocal chain, x = a0 + 1/(a1 + 1/(a2 + ...)), and truncating that chain produces the convergents, which are the best rational approximations to x with denominators of their size.
Pi to eight decimals, 3.14159265, expands to the terms [3; 7, 15, 1]. Its convergents are 3/1, 22/7, 333/106, and 355/113. The last of these, 355/113 = 3.14159, is in error by only 2.70e-07. The convergent 355/113 was known to the Chinese mathematician Zu Chongzhi in the 5th century and remained the most accurate rational approximation of pi for nearly a thousand years. Irrational numbers have infinite expansions, while rational numbers terminate, so pi's chain never ends.
The square root of 2, 1.41421356, expands to [1; 2, 2, 2, 2]. That endless run of 2s is the signature of a quadratic irrational, and a periodic expansion corresponds exactly to a quadratic irrational, as root 2's repeating 2s show. Five terms give the convergent 41/29 = 1.41379, in error by 4.20e-04. The number e, 2.71828183, expands to [2; 1, 2, 1, 1] in five terms, ending at the convergent 19/7 = 2.71429, in error by 4.00e-03.
| Input value | Terms [a0; a1, a2, ...] | Convergent | Decimal value | Absolute error |
|---|---|---|---|---|
| pi (3.14159265) | [3; 7, 15, 1] | 355/113 | 3.14159 | 2.70e-07 |
| root 2 (1.41421356) | [1; 2, 2, 2, 2] | 41/29 | 1.41379 | 4.20e-04 |
| e (2.71828183) | [2; 1, 2, 1, 1] | 19/7 | 2.71429 | 4.00e-03 |
Convergents are best approximations
A continued fraction writes a number as an integer plus a reciprocal chain: x = a0 + 1/(a1 + 1/(a2 + ...)), recorded by its terms [a0; a1, a2, ...]. Truncating the chain gives the convergents, which are the best rational approximations to x with denominators of their size. This best-approximation property means no fraction with a smaller denominator gets closer to the true value. A continued fraction calculator uses this property directly: each convergent it produces is guaranteed to be the closest rational approximation available for its denominator size.
The convergents of pi show this property at work. Verified to eight decimals, pi (3.14159265) expands to the terms 3; 7; 15; 1, whose convergents are 3/1, 22/7, 333/106 and 355/113. The last, 355/113 = 3.14159, is in error by only 2.70e-07. The convergent 355/113 was known to the Chinese mathematician Zu Chongzhi in the 5th century and stayed the most accurate rational approximation of pi for nearly a thousand years. The famous pair of 22/7 and 355/113 illustrates how each successive convergent improves on the last while keeping the denominator as small as possible for that level of accuracy.
Other irrational numbers behave the same way. The square root of 2 (1.41421356) expands to 1; 2; 2; 2; 2 — the endless run of 2s is the signature of a quadratic irrational — and five terms give the convergent 41/29 = 1.41379, in error by 4.20e-04. Likewise, e (2.71828183) expands to 2; 1; 2; 1; 1 in five terms, ending at the convergent 19/7 = 2.71429, in error by 4.00e-03. In each case, no fraction with a smaller denominator gets closer to the true value than the convergent shown.
Irrational numbers have infinite expansions; rational numbers terminate. A periodic expansion corresponds exactly to a quadratic irrational, as root 2's repeating 2s show. Because of this structure, a continued fraction calculator can keep generating convergents for an irrational number indefinitely, with each one maintaining the best-approximation property at its denominator size.
Patterns in famous numbers
Continued fractions reveal hidden structure in numbers that decimals hide entirely. A continued fraction writes a number as an integer plus a reciprocal chain: x = a0 + 1/(a1 + 1/(a2 + ...)), recorded by its terms [a0; a1, a2, ...]. Irrational numbers have infinite expansions, while rational numbers terminate. When you put numbers into a continued fraction calculator, some of the most famous constants display striking, memorable patterns.
The square root of 2 (1.41421356) expands to 1; 2; 2; 2; 2 — an endless run of 2s that is the signature of a quadratic irrational. A periodic expansion corresponds exactly to a quadratic irrational, as root 2's repeating 2s show. Five terms give the convergent 41/29 = 1.41379, in error by 4.20e-04. The golden ratio goes further still: its expansion is all 1s, [1; 1, 1, 1, ...], making it the hardest number to approximate by rationals. Its convergents close in more slowly than those of any other irrational.
The constant e (2.71828183) expands to 2; 1; 2; 1; 1 in five terms, ending at the convergent 19/7 = 2.71429, in error by 4.00e-03. Unlike root 2's simple repetition, e's terms follow a longer structured pattern that continues deeper into the expansion, a regularity that has fascinated mathematicians since Euler. Pi, by contrast, shows no known repeating pattern at all. Verified to eight decimals (3.14159265), pi expands to the terms 3; 7; 15; 1, whose convergents are 3/1, 22/7, 333/106 and 355/113. The last, 355/113 = 3.14159, is in error by only 2.70e-07.
Truncating the chain gives the convergents, which are the best rational approximations to x with denominators of their size. The convergent 355/113 was known to the Chinese mathematician Zu Chongzhi in the 5th century and stayed the most accurate rational approximation of pi for nearly a thousand years. That a fraction with such small denominators can capture pi so tightly is exactly the kind of result continued fractions make visible — a result decimals alone never reveal.
Limits: input precision
A continued fraction writes a number as an integer plus a reciprocal chain: x = a0 + 1/(a1 + 1/(a2 + ...)), recorded by its terms [a0; a1, a2, ...]. Truncating the chain gives the convergents, which are the best rational approximations to x with denominators of their size. Irrational numbers have infinite expansions; rational numbers terminate. A periodic expansion corresponds exactly to a quadratic irrational, as root 2's repeating 2s show. But when you feed a finite decimal into a continued fraction calculator, the expansion is only as trustworthy as the decimal digits you provided.
Finite decimal input caps how many terms are trustworthy. The expansion of a rounded decimal eventually becomes meaningless noise. Consider pi to eight decimals (3.14159265). It expands to the terms 3; 7; 15; 1, whose convergents are 3/1, 22/7, 333/106 and 355/113. The last, 355/113 = 3.14159, is in error by only 2.70e-07. The convergent 355/113 was known to the Chinese mathematician Zu Chongzhi in the 5th century and stayed the most accurate rational approximation of pi for nearly a thousand years. Past those terms, the continued fraction of the rounded decimal diverges from the true continued fraction of pi, producing terms that reflect only the rounding error.
The same limit applies to other constants. The square root of 2 (1.41421356) expands to 1; 2; 2; 2; 2 — the endless run of 2s is the signature of a quadratic irrational — and five terms give the convergent 41/29 = 1.41379, in error by 4.20e-04. The true expansion of the square root of 2 repeats 2 forever, but the decimal input supplies only eight digits, so terms beyond what those digits support are artifacts of truncation, not genuine structure. Likewise, e (2.71828183) expands to 2; 1; 2; 1; 1 in five terms, ending at the convergent 19/7 = 2.71429, in error by 4.00e-03.
The practical takeaway is simple: the fewer decimal digits you enter, the fewer convergents you can trust. A continued fraction calculator cannot recover information that the rounding removed. If you need more terms, supply more digits — or, when the number is known to be irrational, use a symbolic form rather than a rounded decimal so the expansion reflects the true number rather than the approximation you typed in.
FAQs
How do you expand a number into a continued fraction?
Repeatedly take the integer part and invert the remainder. For pi, this gives 3, then 7, then 15, then 1, written as 3; 7; 15; 1. Each step produces the next term in the chain, building the continued fraction representation step by step from the original number.
What are convergents?
Convergents are the fractions you get by truncating the chain. For pi, the convergents are 3/1, 22/7, 333/106, and 355/113. Each convergent is the best approximation with a denominator that size or smaller, meaning no fraction with a smaller denominator comes closer to the target value.
Why does root 2 give endless 2s?
The continued fraction for root 2 is all 2s after the first term: 1; 2; 2; 2; 2. This pattern repeats forever because root 2 is a quadratic irrational. Five terms give the convergent 41/29, which approximates root 2 with improving accuracy as more terms are added.
What is the best fraction for pi?
The best fraction for pi is 355/113, the fourth convergent of pi, accurate to 2.70e-07. This approximation was found by Zu Chongzhi in the 5th century. No fraction with a denominator of 113 or smaller comes closer to pi, making it the optimal rational approximation at that size.
Do continued fractions always end?
No. Irrationals expand forever; only rationals terminate. A repeating pattern in the continued fraction means the number is a quadratic irrational. So rational numbers produce finite expansions, while irrational numbers produce infinite ones, with periodic patterns specifically characterizing quadratic irrationals.
What are continued fractions used for?
Convergents solve gear-ratio, calendar, music-tuning, and Diophantine approximation problems where a fraction must be close but small. They provide the best rational approximations to a given number, making them useful in engineering, astronomy, and music theory whenever you need simple fractions that stay near a target value.