Best Rational Approximation Generator
Converting a decimal to a fraction is easy if you allow any denominator; the interesting question is which fraction is closest when the denominator is capped — by a gear tooth count, a drill size, or a time signature. This walks the Stern-Brocot tree to find it in a few steps, then proves the answer by testing every single denominator within the limit, and shows what naive rounding would have given instead.
What this generator does
Descends the Stern-Brocot tree, taking mediants to narrow in on the target until the denominator limit is reached. The result is then verified exhaustively against every denominator within the limit, and compared against simply rounding.
How to use this tool
- Enter the value you want to approximate, in thousandths.
- Set the largest denominator you can accept.
- Read the closest fraction and how far off it is.
- Compare it against rounding to the largest denominator — often much worse.
Understanding the controls
- Target value
- Entered in thousandths so no decimal typing is needed — 3142 means 3.142.
- Largest denominator allowed
- The cap. The answer often uses a much smaller denominator than this and is still closer than anything using the largest one.
Common use cases
- Choosing gear ratios or pulley sizes with a tooth-count limit
- Converting a measurement to the nearest usable fraction
- Finding a simple fraction that is nearly as accurate as an awkward one
- Teaching why rounding to a fixed denominator is not the best method
- Reducing a timing ratio for music or animation
How this generator works
The Stern-Brocot tree contains every positive fraction exactly once, in lowest terms. Starting from the interval around the target, taking the mediant of the two endpoints repeatedly narrows in on it, and the denominators only grow when they must — so the limit is reached in a handful of steps rather than by searching. Before display the answer is checked exhaustively: for every denominator up to the limit, the nearest numerator is tried, and none may come closer.
Randomness and fairness
Nothing here is random. A target and a limit have exactly one closest fraction, up to ties.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- The target is entered in thousandths, so a value needing more precision than that has to be scaled first.
- Ties are resolved in favour of the fraction the search reaches first, and both are equally good.
- The comparison against rounding is illustrative — for some targets rounding happens to give the same answer.
- Denominator limits above a thousand are rejected, since the exhaustive verification would become slow.
Privacy and your data
Everything is computed in your browser. The value and limit you enter are never transmitted, stored or included in analytics.
Related generators
- Continued Fraction GeneratorExpands any fraction into its continued fraction and lists the convergents, each proved to be the best approximation for its denominator.
- Farey Sequence GeneratorLists every fraction between 0 and 1 with a bounded denominator, in order, with the neighbour identity checked on every consecutive pair.
- Repeating Decimal GeneratorTurns a fraction into its decimal expansion with the repeating block marked, and checks the period against the multiplicative order of ten.
- Random Fraction GeneratorA proper fraction, automatically simplified to its lowest terms, with its decimal equivalent shown.