Float to Rational Fraction Converter

Find the simplest rational fraction approximating a decimal

Ad placeholder (leaderboard)

This converter turns a decimal number into the simplest fraction that approximates it within a denominator you choose. It is useful for recovering a clean ratio from a measurement, finding a gear or pulley ratio, or expressing a constant like pi as a friendly fraction such as 355/113.

How it works

The tool walks the Stern-Brocot tree, a structure that lists every reduced positive fraction exactly once. It separates the whole part from the fractional part, then searches the fractional part between the bounds 0/1 and 1/1. At each step it computes the mediant of the current bounds:

mediant(a/b, c/d) = (a + c) / (b + d)

If the mediant is below the target it becomes the new lower bound, otherwise the new upper bound, narrowing in like a binary search. The search stops once the denominator would exceed your limit, keeping the best (lowest-error) fraction seen. Because every Stern-Brocot fraction is already in lowest terms, no extra reduction is needed.

Tips and example

Try 3.14159265 with a maximum denominator of 10000: the tool returns 355/113, a famously accurate rational approximation of pi with an error under a millionth. Raising the denominator limit always gives an approximation at least as good, while lowering it produces simpler but coarser fractions. If your decimal is exactly representable — for instance 0.375 with a limit of 8 — the result is exact with zero reported error.

Ad placeholder (rectangle)