Fraction Approximator

Convert any decimal to its closest fraction using the continued fraction algorithm. Shows all convergents with error values.

Last reviewed: April 2026

New to this tool? Click here for instructions

Enter a decimal and click Approximate to find the closest fraction.

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.

  1. 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.
  2. 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.
  3. Third convergent: 333/106. Adding the partial quotient 15 yields 333/106 = 3.141509... — error 8.32 × 10⁻⁵, about 1 part in 38,000.
  4. 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.

Convergents of π with Denominators ≤ 1000
Convergent Decimal Value Absolute Error Order of Magnitude Historical Note
3/13.0000001.42 × 10⁻¹~1 in 7Integer floor; trivial
22/73.1428571.26 × 10⁻³~1 in 2,500Archimedes, <240 BC
333/1063.1415098.32 × 10⁻⁵~1 in 38,000Intermediate; rarely cited
355/1133.1415932.67 × 10⁻⁷~1 in 12 millionZu Chongzhi, ~480 AD
Each successive convergent improves accuracy by roughly two orders of magnitude with only a modest increase in denominator. 355/113 sits just before the partial quotient 292, which is why it remains the best low-denominator approximation by a wide margin.
Convergents of π: denominator vs. log-error Log-scale plot of absolute error versus denominator for the first five convergents of pi. Each successive convergent drops error by roughly two orders of magnitude. 355/113 sits dramatically below the trendline because of the unusually large partial quotient 292 that follows it in the continued fraction expansion. 10⁰ 10⁻² 10⁻⁴ 10⁻⁶ 10⁻⁸ 10⁻¹⁰ 1 10 100 1000 Denominator q (log scale) Absolute error |π - p/q| (log scale) Hurwitz bound 1/(√5·q²) 3/1 err 0.142 22/7 err 0.00126 Archimedes 333/106 err 8.32e-5 355/113 err 2.67e-7 Zu Chongzhi, ~480 AD far below Hurwitz bound: a₃₊₁ = 292 Convergent of π Hurwitz 1/(√5·q²)
Log-log plot of absolute error vs. denominator for the first four convergents of π. The dashed grey line shows the Hurwitz theoretical bound 1/(√5·q²) — the best you can ever guarantee for any irrational. 355/113 (highlighted) sits well below this line because the partial quotient 292 immediately follows it, producing a one-time accuracy boost that is mathematically rare and historically remarkable.

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.

Decimal-to-Fraction Methods Compared
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
This tool is most useful when you want to see every step of the convergent sequence, not just the final answer. For scripted batch conversion, Python's 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.

Related Tools

The fraction approximator pairs naturally with several other math and number-theory tools on this site. The Prime Tester is useful for verifying that a simplified fraction is genuinely in lowest terms — if both numerator and denominator are prime, no further reduction is possible. The Digital Root Calculator exposes the divisibility-by-9 property that underlies many fraction-simplification shortcuts. For exploring the recurrence relations behind continued fraction convergents, the Fibonacci Generator shows the convergents of the golden ratio: 1/1, 2/1, 3/2, 5/3, 8/5, 13/8 — successive Fibonacci ratios.

If your decimal came from a measurement involving angles or clock positions, the Clock Angle Calculator handles the modular-arithmetic side of the problem before you reach the fraction step. For workflows that need bit-level precision rather than fraction-level precision — common in DSP and microcontroller programming — pair this tool with the Bitwise Calculator to translate between the rational approximation and its fixed-point binary representation.

Frequently Asked Questions

A continued fraction expresses a real number as an integer plus the reciprocal of another integer plus the reciprocal of another, recursively: a₀ + 1/(a₁ + 1/(a₂ + 1/(a₃ + ...))). The integer coefficients a₀, a₁, a₂, ... are called the partial quotients, and the sequence is written compactly as [a₀; a₁, a₂, a₃, ...]. Truncating the expansion at any point produces a convergent — a rational approximation that is provably the best possible for any denominator at or below its own. Continued fractions for rational numbers terminate; expansions for irrational numbers continue forever. Periodic continued fractions correspond exactly to quadratic irrationals like √2, a result first proven by Lagrange.
22/7 equals 3.142857..., which agrees with π = 3.14159265... to three significant figures with an error of roughly 0.00126 — about 4 parts in 10,000. It is the second convergent of π's continued fraction expansion [3; 7, 15, 1, 292, 1, 1, 1, 2, ...], and it has been used since Archimedes' time as a working substitute for π in carpentry, surveying, and back-of-envelope calculation. Crucially, 22/7 is also slightly larger than π — Archimedes proved in the third century BC that 223/71 < π < 22/7, bounding π between two simple fractions. The popularity of 22/7 made July 22 'Pi Approximation Day' as a counterpart to March 14's Pi Day.
JavaScript and most modern languages use IEEE 754 double-precision floating-point, which stores numbers in 64 bits as a sign, exponent, and 52-bit mantissa. Many decimal values that look clean — 0.1, 0.2, 0.3 — cannot be represented exactly in binary because their decimal expansion does not terminate in base 2. The literal 0.1 is actually stored as 0.1000000000000000055511151231257827021181583404541015625. When this tool receives 0.1 as input, it sees that exact stored value, and the continued fraction algorithm may produce a longer expansion than mathematics suggests. To get the cleanest fraction, either round the input first or set a generous max denominator that still triggers algorithm termination at the intended convergent.
Diophantine approximation is the branch of number theory concerned with how well real numbers can be approximated by rationals — that is, by fractions p/q with integer numerator and denominator. The central question is: given a real number α and a denominator bound q, what is the smallest possible error |α − p/q|? Hurwitz's theorem (1891) gives a tight universal bound: for every irrational α there exist infinitely many p/q with |α − p/q| < 1/(√5 · q²), and the constant √5 cannot be improved without restricting α. Convergents of the continued fraction expansion of α achieve this bound, which is why they are called the "best rational approximations." The field underlies modern results on transcendence and equidistribution, and forms part of the substrate for cryptographic lattice attacks.
For a repeating decimal like 0.333... or 0.142857142857..., the trick is to multiply by a power of 10 that shifts one period left, then subtract. For 0.333..., let x = 0.333...; then 10x = 3.333...; subtracting gives 9x = 3, so x = 3/9 = 1/3. For 0.142857142857..., the repeat block is six digits long, so multiply by 10⁶: 10⁶·x − x = 142857, giving x = 142857/999999 = 1/7. This tool automates the same result through its continued fraction expansion: enter 0.142857 and you'll see 1/7 emerge as a convergent. For decimals with a non-repeating prefix and then a repeating part — like 0.16666... = 1/6 — combine both techniques: split into the non-repeating part plus the geometric series for the repeating tail.
The Stern-Brocot tree is a binary tree containing every positive rational number in lowest terms, exactly once. It is built by starting with the two boundary fractions 0/1 and 1/0 (treated as "infinity") and inserting the mediant — (a+c)/(b+d) — between every adjacent pair, repeating forever. The root is 1/1; its left subtree contains all fractions less than 1, its right subtree all fractions greater than 1. Any irrational number has a unique infinite path through the tree, and the convergents of its continued fraction expansion correspond to the "turning points" where that path switches direction between left and right children. The Stern-Brocot tree is computationally equivalent to the continued fraction algorithm — both are different surface views of the same underlying mediant construction, which dates to Moritz Stern (1858) and Achille Brocot (1861, who used it for watch gear design).
No — division by zero is undefined in standard arithmetic, and a fraction with denominator 0 is not a valid rational number. The tool guards against this in Simplify mode: entering a denominator of 0 triggers a status message rather than producing output. Mathematically, you can extend the rationals with a "point at infinity" to handle expressions like 1/0 — this is what projective geometry and the Stern-Brocot tree's 1/0 endpoint formalize — but that is a separate algebraic structure, not the rationals. In code, IEEE 754 floating-point handles division by zero by returning Infinity or NaN, but those values do not have a finite fraction representation, so passing them to the approximator would yield no meaningful result.
355/113 = 3.1415929203... matches π to seven significant figures with an error of about 2.67 × 10⁻⁷ — roughly one part in four million. By Diophantine standards this is extraordinary: π's continued fraction expansion is [3; 7, 15, 1, 292, 1, ...], and the unusually large partial quotient 292 immediately after 355/113 means the next convergent jumps far ahead in accuracy with only a small bump in denominator size. In other words, 355/113 sits just before a "gap" in the convergent sequence, and no fraction with denominator under about 33,000 can do better. This approximation was discovered by Chinese astronomer Zu Chongzhi (祖治之) around 480 AD — over a thousand years before European mathematicians reached comparable precision. It is easy to remember (113 355 → split the digits) and remained the most accurate practical approximation of π in use until the 17th century.