Decimal to Continued Fraction Calculator

Enter a decimal number to expand it as a continued fraction.

Result

[3; 7, 15, 1, 292]
5

How it is calculated

The tool runs the standard continued-fraction loop. Take the integer part of the current value x as the next term a, then set x = 1 / (x − a) and repeat. The result is written as [a0; a1, a2, …]. A typed decimal is treated as the exact fraction it spells (3.14159 is 314159/100000), so the terms are exact integer arithmetic with no floating-point noise, and the expansion simply ends when the remainder reaches zero. The loop also stops at the maximum number of terms. The default is 10; a blank box or a value below 1 uses 10, a fraction is cut down to a whole number, and the limit never goes above 50. Negative numbers use the floor, so −2.75 gives [−3; 4]. Input that is not a number, or whose size is above 1015, shows no result.

Worked example

Expand 3.14159265358979 with a maximum of 5 terms. Integer part 3, remainder 0.14159…, inverse 7.0625…, so the next term is 7. Remainder 0.0625…, inverse 15.9966…, term 15. Next: term 1, then 292. The tool shows [3; 7, 15, 1, 292] and 5 terms. Cutting the expansion after 1 gives 3 + 1/(7 + 1/(15 + 1/1)) = 355/113 ≈ 3.14159292, a close fraction for this value.

Try this example →

Common mistakes

  • Typing a rounded decimal, such as 3.14159 for π, and expecting π's expansion. The tool expands exactly the number you typed, so after the first few terms the digits differ from π's and the expansion ends early.
  • Expecting a never-ending list for an irrational number. A typed decimal is always a finite fraction, so the expansion terminates; only the first terms say something about the irrational number behind it.
  • Reading the semicolon as a comma. The first number is the whole part, a0; only the later ones are the inverted steps.
  • Expecting a negative number to give a negative first term followed by the positive digits of its fraction part as you would write by hand. The tool uses the floor, so −2.75 is [−3; 4].
  • Setting the maximum to 0 or a fraction to get a shorter result. A value below 1 falls back to 10 terms, and a fraction is cut down to a whole number.

About this calculator

A continued fraction writes a number in the form [a0; a1, a2, a3, …], built by repeatedly taking the integer part of a value and then inverting and continuing with what's left over, a process that, for a rational decimal, eventually terminates, and for an irrational number like π continues indefinitely, with each additional term giving a better rational approximation of the original value.

This representation has real uses beyond pure curiosity: continued fractions produce the best possible rational approximations of a number for a given denominator size, which is exactly how the ratio 355/113 was found as a remarkably accurate approximation of π, and the same technique underlies historical calendar reforms (finding simple fractions close to the length of a solar year) and musical tuning systems (approximating frequency ratios with small integers).

Enter a decimal number and choose how many terms to expand, and this calculator shows its continued fraction representation [a0; a1, a2, …].

Was this helpful?

You can pick up to 3 reactions.

Comments (0)

  • Be the first to comment.

Popular calculators

All Calculators