
Fraction Approximator
Convert any decimal to its closest fraction using the continued fraction algorithm. Shows all convergents with error values.
Last reviewed: April 2026New to this tool? Click here for instructions
Convert any decimal value into its closest rational fraction, with full visibility into every convergent the continued fraction algorithm produces along the way. Enter a decimal, set a denominator ceiling, and the tool returns the best rational approximation under that bound — together with the partial quotients, decimal value, and error of each intermediate convergent. Every calculation runs entirely in your browser; the decimal you enter is never uploaded or logged.
What This Tool Does
The Fraction Approximator solves a deceptively simple-sounding problem: given a decimal number, what is the closest fraction you can write with a bounded denominator? Behind that question sits roughly two centuries of number-theoretic machinery — continued fractions, the Stern-Brocot tree, Diophantine approximation, and the Euclidean GCD algorithm — and this tool surfaces all of it interactively.
Three modes cover the common workflows. Approximate takes a decimal input and a maximum denominator and returns the best rational p/q with q at or below your bound, along with every intermediate convergent of the continued fraction expansion. Simplify takes an existing fraction and reduces it to lowest terms using the Euclidean GCD. Reference displays a curated table of frequently-needed decimal-to-fraction conversions for quick lookup — common cooking measures, fundamental constants, and recognizable repeating decimals.
Internally, the approximator implements the continued fraction algorithm: starting from your decimal x, extract the integer part a₀ = ⌊x⌋, subtract it, invert the remainder, and repeat. The resulting sequence [a₀; a₁, a₂, a₃, ...] is the continued fraction expansion. Truncating after each step produces a convergent — a fraction p/q that is provably the best rational approximation to x for any denominator at or below q. The tool generates convergents one at a time until either the denominator exceeds your ceiling or the remainder drops below 10⁻¹⁰.
How to Use It
The workflow is direct: enter a decimal, pick a constraint, and read the results. The constraint is what determines which convergent the tool returns as "best."
Entering Your Decimal
Type any decimal number into the input field at the top of the Approximate panel — positive, negative, integer-valued, or fractional. The parser accepts standard decimal notation (3.14159, -0.5, 2.71828) and treats trailing dots as zeros. Scientific notation such as 1.5e-3 also parses correctly because it goes through JavaScript's parseFloat. Hit Enter or click the Approximate button to compute.
Setting the Denominator Ceiling
The Max denominator field caps how large the bottom of the returned fraction is allowed to be. A ceiling of 10 forces simple fractions like 1/3 or 22/7; a ceiling of 1000 lets the algorithm find tighter approximations like 355/113 for π; a ceiling of 1,000,000 gives you essentially the exact rational representation of your floating-point input. The default of 1000 strikes a useful balance — small enough to keep fractions human-readable, large enough to capture the most common "famous" rational approximations of mathematical constants.
Reading the Convergents Table
Below the headline result, a table lists every convergent produced during the expansion. Each row shows the fraction, its decimal value, the absolute error compared to your input, and the partial quotients [a₀; a₁, a₂, ...] that produced it. The convergent highlighted in green is the last one whose denominator fit under your ceiling — the tool's answer. Reading the table top-to-bottom gives a clean view of how each new partial quotient brings the approximation closer to your input, often by an order of magnitude per step.
Switching to Simplify or Reference Mode
The mode chips at the top of the tool switch between approximator workflows. Simplify reduces a fraction you already have — enter 24/36, click Simplify, and the tool returns 2/3 along with the GCD that was divided out. Reference displays a static table of common decimal-to-fraction conversions, useful when you need a quick mental shortcut without typing anything.
Worked Example: Approximating π with Denominators ≤ 1000
- Input
3.14159265(eight-digit decimal approximation of π)- Max denominator
1000- Continued fraction expansion
[3; 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, ...]
Pi's continued fraction is the most celebrated example in the entire field — partly because of its irregular, seemingly random partial quotients, and partly because one particular convergent is so accurate it has its own millennium-old story.
- First convergent: 3/1. The integer part of π is 3, giving the trivial convergent 3/1 = 3.000000 with error 0.14159 — roughly 4.5% off.
- Second convergent: 22/7. The next partial quotient is 7, producing 22/7 = 3.142857... — error 0.00126, about 1 part in 2,500. Archimedes used this as an upper bound for π in the third century BC.
- Third convergent: 333/106. Adding the partial quotient 15 yields 333/106 = 3.141509... — error 8.32 × 10⁻⁵, about 1 part in 38,000.
- Fourth convergent: 355/113. The partial quotient 1 produces 355/113 = 3.141593... — error 2.67 × 10⁻⁷, about 1 part in 12 million. The tool stops here because the next convergent (103993/33102) has denominator 33,102, exceeding the ceiling of 1000.
What makes 355/113 extraordinary is the partial quotient that comes immediately after it: 292. Recall that a large partial quotient signals that the next convergent will be a dramatic improvement in accuracy with only a moderate increase in denominator. A partial quotient of 292 is unusually large for any continued fraction expansion — it means 355/113 sits at a kind of plateau in the approximation hierarchy, with no fraction of comparable simplicity coming close until denominators reach the tens of thousands. By Diophantine standards this is an aberration, and it is the reason 355/113 stays a useful working approximation for π in any context where seven decimal digits suffice.
Chinese astronomer and mathematician Zu Chongzhi (祖治之) discovered 355/113 around 480 AD. Working from Liu Hui's polygon method, Zu computed π to seven decimal places and identified 355/113 as the milü ("close ratio") — a precision unmatched in any culture for over nine hundred years. The fraction is also a remarkable mnemonic: write 113355, split it in the middle, and you have denominator-then-numerator. This memorability, combined with seven-figure accuracy, makes Zu Chongzhi's approximation arguably the single most cost-effective rational ever discovered.
| Convergent | Decimal Value | Absolute Error | Order of Magnitude | Historical Note |
|---|---|---|---|---|
3/1 | 3.000000 | 1.42 × 10⁻¹ | ~1 in 7 | Integer floor; trivial |
22/7 | 3.142857 | 1.26 × 10⁻³ | ~1 in 2,500 | Archimedes, <240 BC |
333/106 | 3.141509 | 8.32 × 10⁻⁵ | ~1 in 38,000 | Intermediate; rarely cited |
355/113 | 3.141593 | 2.67 × 10⁻⁷ | ~1 in 12 million | Zu Chongzhi, ~480 AD |
Common Use Cases
The decimal-to-fraction problem shows up in any field that needs to map a measured or computed real value onto something physically realizable — gears, dividers, mixing ratios, integer arithmetic. Below are the five workflows where this tool gets the most use.
Mechanical Gear Ratios
Gear teeth come in integer counts, but the desired output speed often arrives as a decimal — "reduce 3000 RPM by 4.7×" or "drive a wheel at 0.382 turns per revolution of the input shaft." The Fraction Approximator returns the simplest gear ratio that fits within your tooth-count budget. For 4.7, with a max denominator of 30, the best convergent is 47/10. With a max of 100, you reach 1410/300, but no improvement in accuracy — 47/10 is exact. Achille Brocot, co-discoverer of the Stern-Brocot tree, derived it specifically for designing watch gear ratios in 1861.
Microcontroller Clock Dividers
Embedded systems frequently generate one clock frequency from another by integer division. Producing a 9600 Hz baud-rate clock from a 16 MHz system clock requires dividing by 1666.667 — which rounds to 1667 with an integer divider, introducing 0.04% error. The Fraction Approximator finds the optimal fractional divider when the chip supports them: 16000000/9600 = 5000/3, so a fractional divider of 5000 numerator over 3 denominator hits the target exactly. STMicro, NXP, and Microchip all expose continued-fraction-style fractional dividers in their UART, SPI, and SAI peripherals for precisely this reason.
Audio Sample-Rate Conversion
Converting between common digital audio sample rates is a fraction problem in disguise. The ratio 48000/44100 = 160/147 is the canonical CD-to-DAT conversion factor, and it arises directly from continued-fraction reduction of 48000/44100 to lowest terms via the Euclidean GCD (GCD = 300). The fact that 160 and 147 are both small enough to fit in a polyphase resampler's filter bank is why this conversion is so much cheaper than, say, 96000-to-44100 (which reduces to 960/441 — still tractable but heavier). Enter 1.088435 (the decimal form of 48000/44100) with a max denominator of 200 in this tool and you'll see 160/147 appear as the best convergent.
Recipe and Measurement Scaling
Doubling a recipe is easy; scaling one by 1.333 is awkward unless you can recognize that 1.333 = 4/3 and convert "1.333 cups of flour" into "1⅓ cups." The Fraction Approximator handles this conversion automatically — type 1.333, max denominator 20, and the tool returns 4/3 with a small residual error reflecting the truncation in the input. For inputs that genuinely don't reduce to small fractions (recipe scaling factor of, say, 1.732), the tool falls back to the best low-denominator approximation, which may be useful enough for kitchen work even when it isn't mathematically exact.
Display DPI and Pixel Calculations
Asking "what fraction of 96 DPI is 144 DPI?" reduces immediately: GCD(144, 96) = 48, so 144/96 = 3/2. But the question gets harder when you start with a measured PPI like 458 (iPhone 14 Pro): expressing 458 PPI as a fraction of a reference 326 PPI gives 458/326, which the Simplify mode reduces to 229/163. Knowing that 229 and 163 are both prime tells you immediately that there's no further simplification possible — the ratio is exact only at those integer values.
Edge Cases and Numerical Pitfalls
A few subtleties matter when you push the approximator with unusual inputs. Each of these is a real boundary that comes up in practice, not a contrived corner case.
Repeating Decimals: 1/3 = 0.333...
The decimal 0.333... with infinitely many trailing 3s equals exactly 1/3. When you type 0.333333 (six 3s) into the input, the tool returns 1/3 with a microscopic residual error — about 3 × 10⁻⁷, which is the difference between 0.333333 and 1/3. To get 1/3 with zero residual, type 0.3333333333 (ten 3s); now the input is closer to 1/3 than to any other simple fraction at any denominator ceiling the tool checks. For pure repeating decimals like 0.142857142857... (= 1/7) or 0.090909... (= 1/11), the algorithm converges in just a few steps.
Terminating Decimals with Many Digits: 1/128 = 0.0078125
The fraction 1/128 expands to 0.0078125 — exactly seven decimal digits, no repeat, because 128 = 2⁷ and powers of 2 have terminating decimal expansions. Type 0.0078125 with a max denominator of 200, and the tool returns 1/128 with zero error. This is the cleanest case for the algorithm: a terminating decimal whose denominator factors into 2s and 5s always has an exact rational form, and the continued fraction algorithm finds it in O(log q) steps.
Irrational Numbers: √2 Has No Finite Fraction
The square root of 2 cannot be written as p/q for any integers p and q — a fact Hippasus of Metapontum allegedly proved around 500 BC, an event that may or may not have led to his being thrown overboard for upsetting the Pythagorean worldview. When you enter 1.41421356 (the eight-digit approximation), the tool produces a sequence of convergents — 1/1, 3/2, 7/5, 17/12, 41/29, 99/70, ... — each twice as accurate as the last. The continued fraction expansion of √2 is the periodic sequence [1; 2, 2, 2, 2, ...], a hallmark of all quadratic irrationals.
Continued Fraction Termination
The algorithm halts in one of three ways: (1) the remainder drops below 10⁻¹⁰, signaling that the input is effectively rational at floating-point precision; (2) the next convergent's denominator would exceed your ceiling; or (3) the iteration counter hits 30, which is the hard-coded safety limit. The third case rarely triggers for well-conditioned inputs but can fire for adversarial decimals that produce arbitrarily many tiny partial quotients.
Floating-Point Input: Hidden Imprecision
IEEE 754 doubles cannot represent 0.1 exactly — the literal 0.1 is stored as 0.1000000000000000055511151231257827021181583404541015625. When you type 0.1 into the input, the tool sees that exact stored value and may produce a fraction with a slightly larger denominator than 1/10. To get 1/10 explicitly, type 0.1 with a max denominator of 100, and the algorithm will return 1/10 well before the stored imprecision matters. The general guidance: prefer modest max-denominator ceilings when working with inputs that are clearly meant to be simple round-number decimals, and large ceilings only when you actually want the exact rational representation of the floating-point bits.
Behind the Scenes
The Continued Fraction Algorithm
The algorithm consists of a tight loop: at each step, take the integer part of the current value as the next partial quotient aₐ, subtract it, and invert the remainder. Two recurrence relations track the numerator h and denominator k of each convergent:
hₐ = aₐ·hₐ₋₁ + hₐ₋₂
kₐ = aₐ·kₐ₋₁ + kₐ₋₂
with initial conditions h₋₁ = 1, h₀ = a₀, k₋₁ = 0, k₀ = 1. The convergents are pₐ/qₐ = hₐ/kₐ. This recurrence is the same one Aryabhata used in 499 AD (in his Aryabhatiya, applied to astronomical period calculations) and that Euler systematized in the 18th century. It is O(log q) in the size of the denominator — meaning even denominators in the millions converge in fewer than 50 steps.
The Stern-Brocot Tree
The Stern-Brocot tree provides a geometric view of the same algorithm. Imagine a binary tree where every node is a fraction in lowest terms. The root is 1/1; each node's left child is its mediant with the nearest smaller ancestor, and its right child is the mediant with the nearest larger ancestor. Every positive rational appears exactly once, and any irrational defines a unique infinite path. The convergents of an irrational's continued fraction expansion correspond to the "turning points" in its Stern-Brocot path — the points where the descent switches between left and right children. This connection means the continued fraction algorithm and the Stern-Brocot tree are different surface views of the same underlying mediant construction.
Diophantine Approximation and Hurwitz's Theorem
The field of Diophantine approximation studies how closely rationals can approximate reals. The cornerstone result is Hurwitz's theorem (1891): for every irrational α, there exist infinitely many fractions p/q with |α − p/q| < 1/(√5 · q²), and the constant √5 cannot be improved without restricting the class of α. The bound is sharp — the golden ratio φ = (1+√5)/2 saturates it, because φ's continued fraction is the all-1s sequence [1; 1, 1, 1, ...], the slowest-converging possible. Every convergent of every continued fraction satisfies Hurwitz's bound; this is what justifies the claim that convergents are the "best rational approximations."
The Euclidean GCD Algorithm
The Simplify mode uses the Euclidean algorithm: GCD(a, b) = GCD(b, a mod b), terminating when b = 0. To reduce a fraction p/q to lowest terms, compute g = GCD(p, q), then return (p/g)/(q/g). The Euclidean algorithm is O(log min(p, q)) — astonishingly fast even for million-digit numbers — and is the oldest non-trivial algorithm in continuous use, dating to Euclid's Elements Book VII, Proposition 1 (~300 BC). The continued fraction algorithm is, formally, the Euclidean algorithm extended to real-valued inputs: the partial quotients aₐ are exactly the integer quotients that appear at each step of the GCD when applied symbolically to x and 1.
Comparison: This Tool vs. Other Decimal-to-Fraction Methods
The decimal-to-fraction problem has multiple software solutions, each with different trade-offs in precision, denominator control, and integration with surrounding workflows. The table below compares this tool against the four most common alternatives, focusing on what each does well and when to prefer it.
| Method | Algorithm | Denominator Control | Best For | Trade-offs |
|---|---|---|---|---|
| This Tool | Continued fraction with convergent table | Integer ceiling; explicit | Exploring how each convergent compares; learning the algorithm | Browser-only; no scripting hook |
LibreOffice =FRACTION() |
Hybrid: continued fraction or Stern-Brocot, capped at a chosen number of digits | Digit count (1, 2, 3 digits in the denominator) | Spreadsheet-embedded conversions for finance, inventory | No visibility into intermediate convergents; rounding behavior varies by version |
Wolfram Alpha FromContinuedFraction |
Full symbolic continued fraction with arbitrary precision | None by default; can request convergents at specific depths | Number-theoretic exploration with symbolic constants (π, e, φ) | Requires internet; rate-limited free tier; verbose UI |
Python Fraction.from_float(x).limit_denominator(n) |
Best rational approximation under a denominator bound (Stern-Brocot equivalent) | Integer bound n on denominator | Scripted workflows; pipelines; CI tests | Stdlib only returns the single best fraction, not the full convergent sequence (use fractions._approximate internals or roll your own for the full list) |
| Hand-computed continued fraction | Pencil-and-paper Euclidean reduction | Determined by where you stop | Number theory courses; competition math; algorithm understanding | Slow for inputs with more than 4-5 partial quotients; arithmetic errors compound |
fractions module is faster; for symbolic exact arithmetic with named constants, Wolfram Alpha wins. For embedded spreadsheet work, =FRACTION() is the right primitive.Choosing among them is mostly a question of where the input is and where the output needs to go. If you're staring at a decimal in a browser tab and want to understand why the chosen fraction is the best one, this tool's convergent table is the most explanatory. If you have a column of decimals in a spreadsheet, =FRACTION() is the right tool. If you're writing automated tests or a code generator that needs deterministic fractional output, Python's fractions.Fraction.from_float().limit_denominator() is the simplest API.