continued fractions · gcd · repeating decimals · local

Convert between decimals and fractions

Find the best rational approximation for any decimal, or expand any fraction with full repeating-block detection.

Decimal ↔ Fraction Converter
Mode
decimal→fraction
Status
ready
live
Error
0.00e+0
abs diff
Repeating
—
input · numbers
output · result
Best rational approximation
3 / 8
≈ 0.375 · error 0.000e+0
Quick Start

How conversion works

Decimal to fraction uses the continued-fraction algorithm to find the closest rational under your max denominator. Fraction to decimal does long division with remainder tracking to spot repeating blocks.

  1. 01

    Pick a mode

    Decimal → Fraction or Fraction → Decimal.

    Inputs are treated as UTF-8 throughout the pipeline and validated client-side as you type — nothing dispatches until the value is well-formed.

    modeinpututf-8client-sidevalidated
    mode · textd2f · set
    mode = d2f
    loaded · parsedclient-side
  2. 02

    Type the number

    BigInt-aware on the numerator/denominator side.

    Each toggle re-computes through a memoised hook, so flipping options never resets your input and the UI stays snappy on large inputs.

    inputoptionslivememoisedtoggles
    input · memoised0.375 · live
    0.375
    options set · memoisedlive
  3. 03

    Read the math

    Approximation, error, repeating block — whichever applies.

    Randomness — where used — comes from crypto.getRandomValues, never Math.random. Heavy work sits in useMemo.

    mathcomputeinstantlocaldeterministic
    out · instant3/8 · computed
    3 / 8
    computed · instantinstant
  4. 04

    Use the result

    Drop into code, derivations, or design dimensions.

    Copy writes through navigator.clipboard and downloads use a Blob — zero network traffic. Same input plus same options always yield the same bytes.

    usecopydownloadzero-networkreproducible
    ok · copiedready · copied
    Copied
    shipped · ready to shipsuccess
Pro tips

Pro tips for everyday utilities

Reach for crypto.getRandomValues

Cryptographically random for IDs, tokens, salts. Math.random is for animation and games, not security.

Sort IDs lexicographically

UUID v4 has no time ordering. Use ULID or UUID v7 if you need sorted IDs.

Mock data with seeds

Faker-style libraries can be seeded so tests are reproducible. Embed the seed in the fixture file.

Reference cards beat memory

Cheatsheets for Vim, Git, Docker, Linux signals are faster than man pages when you’re mid-flow.

Browser APIs vary

Touch events, gamepads, and clipboard differ across vendors. Feature-detect before use.

Persist in the right place

localStorage for user preferences, sessionStorage for transient state, IndexedDB for structured data.

Use Cases

When to convert

Engineering, woodwork, music theory, education.

Engineering tolerances

Round dimensions to a tractable fraction for milling. Random values come from crypto.getRandomValues — cryptographically secure for tokens, salts, and session IDs. Math.random is deterministic enough for animations but predictable enough to be a security bug.

CSPRNG-backed

Woodwork

Convert 0.625 to 5/8 for tape-measure work. Pair with hashids, ULID, or UUID v7 when you need both random and sortable — useful for primary keys, public-facing IDs, and event log ordering without a sequence column.

reproducible

Music theory

Express tempo or rhythm ratios as fractions. Output is deterministic given the same seed, so fixtures and tests stay reproducible across CI runs and contributor machines. Embed the seed in the fixture file for full replay.

snappy

Repeating digits

Find the period of 1/7 (six digits, 142857). Heavy work runs through useMemo so the UI stays snappy on large inputs. Same input + same options yields identical bytes — the kind of stability snapshot tests rely on.

feature-detected

Education

Demonstrate continued fractions and approximation. Storage tools persist to the right backend: localStorage for user preferences, sessionStorage for transient state, IndexedDB for structured data. Pick the right shelf and quota worries disappear.

deterministic

Layout grids

Translate CSS percentages back to clean fractions. Browser feature detection: clipboard, fullscreen, gamepad, and Web Bluetooth APIs gracefully fall back when unavailable. No surprise white screens on Safari or older Firefox.

production-ready
FAQ

Frequently asked questions

Because 0.333… is infinite. Decimal → Fraction recovers 1/3 from 0.333 if you allow enough denominator space.
BigInt — bounded by your browser memory. Continued fractions cap at 64 steps to keep things fast.
We wrap it in parentheses, e.g. 0.(142857) for 1/7.
Lower values give friendlier fractions but more error. 1 million is a good default for most use cases.
No. All math runs locally in your browser.
Suggest a tool

Something missing?

Tell us what you need. We ship the top requests every two weeks.

Sent straight to the maintainers · no account needed
47 in queue·8 shipped this month
Request queued. Thanks!