Decimal to Fraction Converter finds the simple fraction
Convert a decimal into its simplest fraction, or a fraction into a decimal, in either direction.
Simplest, Not Nearest
The algorithm looks for the simplest fraction inside the tolerance, not the closest one over a fixed denominator.
Digits Decide the Answer
0.333333333 finds 1/3. 0.33 finds 33/100. Both are correct for what was typed.
How do you turn a decimal into a fraction?
At a Glance
A terminating decimal is easy: put the digits over the matching power of ten and reduce. A repeating decimal is the interesting case, because 0.333333333 over a billion is technically correct but useless — what you actually want is 1/3.
Going from a fraction to a decimal is one division. The other direction uses a continued-fraction expansion, which repeatedly takes the whole part of a number and inverts what is left:
x = a₀ + 1 ÷ (a₁ + 1 ÷ (a₂ + …))Each step produces a convergent — a fraction that approximates the decimal better than any simpler fraction can. The algorithm stops as soon as a convergent is within 10⁻¹⁰ of the input, or when the denominator would exceed the cap you set. That is why it finds 1/3 for 0.333333333 rather than reducing 333,333,333/1,000,000,000, which has no common factor to cancel.
Simplification of the final answer uses the Euclidean algorithm, so 375/1000 comes back as 3/8 and the sign always sits on the numerator.
The defaults convert 0.375 into 3/8. The other cases show where the digits you type start to matter.
A terminating decimal: 0.375
The expansion terminates exactly, giving 3/8 with no approximation at all.
A repeating decimal: 0.333333333
Nine threes are within 10⁻¹⁰ of one third, so the first convergent already matches and the answer is 1/3.
A longer repeat: 0.142857142857
The six-digit repeat of one seventh is recognised, and the result is 1/7.
Too few digits: 0.33
Two digits are not close enough to one third, so the honest answer is 33/100 — and that is exactly what was typed.
Capping the denominator: 3.14159265
Left uncapped, this gives 308429/98176. Cap the denominator at 200 and you get the classic 355/113 instead.
The conversion is deterministic, but what you get depends on what you asked for.
The digits you type are the specification. 0.33 and 0.333333333 are different numbers, so they get different fractions. If you know the decimal repeats, type enough of it to be unambiguous — nine digits is plenty for any common repeat.
The denominator cap is a feature. Lowering it forces a simpler approximation, which is exactly what you want for measurements: cap at 16 and 0.313 becomes 5/16, the nearest sixteenth of an inch.
Irrational numbers have no exact fraction. π, √2 and e can only ever be approximated. The result will be a very good rational approximation, never the number itself.
Ten decimal places are shown, and long repeats are truncated. 1/7 displays as 0.1428571429; the fraction is the exact form and the decimal is not.
To calculate with the fractions you get, use the Fraction Calculator. For the greatest common divisor behind the simplification, use the GCF and LCM Calculator.