Continued Fraction Calculator

Convert a decimal into a continued fraction and a fraction.

How it is calculated

The tool repeats one step: take the integer part a = floor(x), subtract it, and invert the leftover, x = 1 / (x - a). The collected integers form [a0; a1, a2, ...]. It stops when the remainder drops below 1e-9 (the number has ended) or when it reaches the number of terms you ask for. That limit must be between 1 and 30; a value below 1 falls back to 10 and a value above 30 is cut to 30.

The fraction is built with the recurrence h(n) = a(n)*h(n-1) + h(n-2) and k(n) = a(n)*k(n-1) + k(n-2), giving h / k. The decimal shown is that fraction divided out to six places, so you can see how close it is to your input. Floating-point input means very long expansions of a decimal like 0.333333 end in huge terms: the tool expands the decimal you typed, not the fraction you had in mind.

Worked example

Enter 3.14159 with 3 terms. Integer part 3, remainder 0.14159. Invert: 1 / 0.14159 = 7.06, so the next term is 7, remainder about 0.0626. Invert: 1 / 0.0626 is about 15.99, so the next term is 15. With three terms the expansion is [3; 7, 15]. The recurrence gives 3/1, then 22/7, then 333/106, so the fraction is 333 / 106, which divides out to 3.141509, close to the 3.14159 you typed.

Try this example →

Common mistakes

  • Asking for more terms to get a 'cleaner' fraction. More terms give a closer fraction but usually with a much larger denominator; for a gear ratio or a ruler fraction a few terms are often the useful answer.
  • Typing a rounded decimal such as 0.333 or 0.33333 and expecting 1/3. The tool expands exactly what you typed, so you get a different, ugly fraction instead.
  • Reading the bracket as a list of equal parts. The first number is the whole part and the rest, after the semicolon, are the nested denominators.
  • Treating the six-place decimal as the input. It is the value of the fraction found, so compare it with your number rather than copying it back.

About this calculator

This calculator expands a decimal number into its continued fraction representation — a sequence of integer terms [a₀; a₁, a₂, a₃, …] found by repeatedly taking the integer part and inverting the remainder — and shows the convergents, the best rational (fraction) approximations obtainable at each step.

Number theory students and programmers use it to find the simplest fraction that closely approximates a decimal (useful for gear ratios, musical tuning, and calendar systems), and it's a classic way to demonstrate why some numbers like π have infinite non-repeating continued fractions while rational numbers terminate.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Watch for an unusually large term in the bracket. It means the fraction just before it is a remarkably good approximation for its size: for π the term 292 follows the fraction 355 / 113, which is already correct to about six decimals. Past roughly ten terms, a decimal typed with 15 digits is mostly expanding its own rounding, so extra terms stop meaning anything. Which decimal are you trying to approximate, and what denominator limit do you have in mind?

Popular calculators

All Calculators