Allin1Tool
ConvertersRuns in your browser

Decimal to Fraction / Fraction to Decimal

Turn a decimal into its closest simple fraction and its exact fraction, or turn a fraction back into a repeating decimal.

Share:

Decimal to Fraction / Fraction to Decimal workspace

Converter Inputs

Continued fractions find the closest fraction within this budget, so 0.333333 becomes 1/3.

Applies to numeric results. Conversions themselves are computed at full precision.

Conversion Output

Enter a value — everything is computed in your browser.

Using Decimal to Fraction / Fraction to Decimal

  1. Choose a direction: decimal to fraction, or fraction to decimal.

  2. Enter the decimal value, or the numerator and denominator.

  3. For decimals, set the largest denominator you will accept — 16 for sixteenths, 64 for fine work, or leave it at 10,000.

  4. Read the approximation, the exact fraction from the digits you typed, the mixed number, and the error between them.

A decimal has two honest fractional answers, and both are shown: the closest fraction within your denominator budget, found by continued fractions, and the literal digits over a power of ten reduced by Euclid's algorithm. Results are echoed back as decimals with any repeating block written in brackets.

Decimal to Fraction

Turn a decimal into a fraction, or a fraction into a decimal. The interesting part is that a decimal has two honest fractional answers, and this page shows you both instead of guessing which one you meant.

Two fractions, two different questions

Type 0.333333 and the panel shows:

  • Best rational approximation: 1/3, with an approximation error of 3.333e-7
  • Exact fraction from the digits entered: 333333/1000000

Both are correct. The first answers "what simple fraction is this decimal probably standing in for?", which is what you want to know when the decimal came from rounding something. The second answers "what fraction is this decimal, exactly?", and that's the question to ask when the digits themselves are the measurement.

The two rows come from different methods. The exact row builds the fraction over a power of ten (333333 over 1,000,000) and reduces it with Euclid's greatest-common-divisor algorithm, which in this case divides by 1 and leaves it alone. The headline row comes from a continued-fraction expansion: it walks the convergents and stops at the last one whose denominator fits your budget. Euclid still runs, but only on the exact-from-digits row.

The denominator budget decides the answer

The budget is a dropdown, and changing it changes the actual result, not just how it's displayed.

Leave it at 10,000 and 3.14159265 returns 355/113 with an error of 2.7e-7. That's the famous approximation Chinese mathematicians had by the fifth century. Drop the budget to 16 and the same input returns 22/7, error 1.3e-3: cruder, but you can express it in sixteenths.

So set it to 16 when the answer has to be readable off a tape measure, 64 for fine woodworking, and leave it high when you want the tidiest fraction available.

Raising it too far undoes the trick. At a budget of 1,000,000, 0.333333 stops being 1/3 and becomes 333333/1000000 with zero error, because that fraction now fits and it's a closer match to the digits you typed. The approximation is only useful while it's constrained, so a larger budget can actually make the answer worse.

Repeating decimals get bracket notation

The result is echoed back as a decimal with the repeating block in brackets. 1/7 is written 0.(142857), 5/6 is 0.8(3), and 7/12 is 0.58(3), with the non-repeating part sitting outside the brackets.

Under the hood it's long division with a memory. The remainder at each step is recorded, and when a remainder comes up again, the digits between the two sightings are the cycle. Brackets are the only notation that tells the truth about these numbers, since 0.142857142857 is a different value from 1/7.

The expansion stops after 40 digits. A fraction with a longer period gets an ellipsis instead of brackets. 355/113 repeats with a period of 112, for example, so it's shown truncated, though the value behind it is still exact.

Signs, mixed numbers and one warning

Negatives are handled properly. -0.75 gives −3/4 and the mixed number −3/4. The previous build returned −1/1, which is a different number altogether, well beyond any rounding error. Values above one produce a mixed number alongside the improper fraction, so 2.5 shows as 5/2 and 2 1/2.

The warning is about how strong the approximation is. Continued fractions are very good at finding the fraction a decimal stands in for, which means they'll find one whether or not it exists. Feed in the golden ratio 1.6180339887 with a budget of 10,000 and you get 10946/6765. Those are two consecutive Fibonacci numbers, correct to nine decimal places, and it's still an approximation of a number with no fractional form at all. So read the error row first. When it says 0 (exact), it is; otherwise you're holding a very good guess.

Nearby number tools

Frequently asked

Why are two different fractions shown for the same decimal?

The headline row is the closest fraction within your denominator budget, found by a continued-fraction expansion. The second is the literal digits over a power of ten, reduced with Euclid's algorithm — so 0.333333 yields both 1/3 and 333333/1000000.

What does the denominator budget change?

It caps how large a denominator the approximation may use, and it changes the answer. At 10,000 the value 3.14159265 returns 355/113; at 16 it returns 22/7, cruder but readable off a tape measure.

What do the brackets in 0.(142857) mean?

They mark the repeating block. The long division records each remainder, and when one recurs the digits between the two sightings are the cycle, so 1/7 is written 0.(142857).

Can it give an exact fraction for pi or the golden ratio?

No, and nothing can — they have no fractional form. It returns very close approximations, such as 10946/6765 for 1.6180339887, so read the approximation error row before treating a result as exact.