Float to Rational Fraction Converter

Find the simplest rational fraction approximating a decimal

Convert any decimal number to the simplest rational fraction within a denominator limit using a Stern-Brocot mediant search. Shows the fraction, its decimal value, and the approximation error. Runs entirely in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How does the Stern-Brocot search work?

The Stern-Brocot tree organizes every positive fraction in lowest terms. Starting from the bounds 0/1 and 1/1, the tool repeatedly takes the mediant (sum of numerators over sum of denominators) and moves toward the target, which finds the simplest fraction at each level of accuracy.

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.

Classic examples worth trying

Some of the most famous rational approximations are fun to verify with this tool:

DecimalDenominator limitBest fractionError
3.141592651022/7+0.000402…
3.1415926510,000355/113-0.00000027…
1.41421356 (√2)10099/70-0.0000051…
1.61803399 (φ)10089/55+0.0000083…
0.333333… (1/3)101/30 (exact)
0.142857… (1/7)101/70 (exact)

The approximation 355/113 for pi is remarkably accurate — known since the 5th century by the Chinese mathematician Zu Chongzhi — and cannot be improved until you allow a denominator of over 33,000. This makes it the best “simple-denominator” approximation of pi in that range.

When this tool is genuinely useful

Gear and pulley ratios. If you measure a gear ratio as a decimal (for example, 0.4286 from a tachometer reading), converting to 3/7 immediately tells you the tooth counts involved and confirms the mechanism is working correctly.

Recipe scaling. A scaling factor of 0.6667 is exactly 2/3. Recognising this avoids imprecise measurements — pour to the 2/3 mark rather than trying to measure 0.6667 of a cup.

Music theory. Frequency ratios in Western tuning are rational numbers. A perfect fifth is 3/2 (1.5), a major third is 5/4 (1.25), and equal temperament’s whole tone is 2^(2/12), which is irrational. Finding the closest simple ratio reveals how well a tuning approximates just intonation.

Display and screen ratios. Screen aspect ratios like 1.7778 resolve immediately to 16/9.

Engineering measurements. A measured dimension of 0.625 inches simplifies to 5/8, which is a standard drill or fastener size that you can then actually buy.

Denominator limit and accuracy trade-off

The denominator limit is the single control over accuracy versus simplicity. Some practical values:

  • 10: very simple fractions only — halves, thirds, quarters, fifths, eighths. High error on irrational numbers.
  • 100: most simple engineering fractions (1/16, 3/7, etc.). Good for measurements in imperial units.
  • 1,000: close approximations of most common constants.
  • 10,000: excellent approximations — 355/113 for pi, 99/70 for √2.
  • 1,000,000: near-perfect; mainly useful for checking whether a decimal is “almost exactly” a simple fraction.

Raising the limit always gives a result at least as accurate as a lower limit, never worse. If your decimal is exactly representable as a fraction within the limit (for example 0.375 = 3/8), the result is exact with zero reported error. All computation runs locally in your browser.