How to use the continued fraction calculator
- Type a decimal such as 3.14159265 or a fraction such as 355/113. The number is used exactly as typed.
- Enter the largest denominator you will accept, to find the closest simple fraction. The 1,000 shown is an example.
- Read the continued fraction in bracket form, the number as a reduced fraction, and the closest fraction within your limit.
- Use the table of convergents to see how each step gets closer and how large the error is.
Formula
a0 = floor(x), then repeat: x = 1 / (x - floor(x)), a_k = floor(x)
convergents: p_k = a_k p_(k-1) + p_(k-2) and q_k = a_k q_(k-1) + q_(k-2), starting from 1/0 and a0/1
a convergent p/q is the best approximation to x among all fractions with a denominator up to q
the closest fraction within a limit may also be a semiconvergent between two convergents
A rational number has a finite continued fraction, found by Euclid's algorithm on its numerator and denominator. The tool works with exact whole numbers, so no rounding enters.
The decimal 3.14159265
The decimal 3.14159265 is the fraction 62,831,853 / 20,000,000. Its continued fraction is [3; 7, 15, 1, 288, 1, 2, 1, 3, 1, 7, 4]. The first convergents are 3, 22/7, 333/106 and 355/113. The fraction 355/113 is 3.14159292, which differs from the number by only about 0.00000027.
With a denominator limit of 1,000 the closest fraction is 355/113. With a limit of 100 it is 311/99, a semiconvergent that is closer than 22/7. With a limit of 10 it is 22/7, and with a limit of 1 it is 3. A limit of 50,000 gives 102928/32763. For -7/3 the expansion is [-3; 1, 2].
What the convergents tell you
Each convergent is the best fraction you can get with a denominator no larger than its own, so they are the natural choices when you need a simple fraction for a measurement, a gear ratio or a musical interval. A large term in the expansion, like 288 above, means the previous convergent is unusually accurate for its size, which is why 355/113 is so good.
Because a typed decimal is treated as exactly that decimal, its expansion ends where the decimal does. It is not an approximation of pi. For ordinary fraction arithmetic use the Fraction Calculator, and to see a fraction as a decimal the Fraction to Decimal Converter.
Limits
Numbers can have up to 40 digits on each side of a fraction. The table shows the first 25 convergents when there are more. The error column shows the distance from the number you typed.
More logic and number tools
For related logic, chemistry and number problems, try the Boolean Expression Simplifier, Chemical Equation Balancer and Chinese Remainder Theorem Solver.
Assumptions and limits
- The number is a decimal or a fraction of whole numbers with at most 40 digits.
- The expansion is exact for the number as typed, with no rounding.
- The denominator limit is a whole number of 1 or more.
- Errors are shown as decimals to twelve places, or as less than that when smaller.
Frequently asked questions
What is a continued fraction?
It writes a number as a whole part plus one over another whole part plus one over another, and so on. The list of whole parts, like [3; 7, 15, 1], is the expansion.
How do I find the best fraction approximation of a decimal?
Compute the continued fraction and its convergents, then check the in-between fractions for the closest one within your denominator limit. The tool does both steps.
Why is 355/113 such a good approximation of pi?
The expansion of pi has a large term, 292, right after 355/113, which means the next step changes the value very little. That makes 355/113 unusually accurate for its small denominator.
Does every number have a finite expansion?
Only rational numbers do. Irrational numbers have expansions that never end, so a typed decimal, which is rational, always ends.