BCBetter Calculators

Decimal to Fraction Calculator

Convert a decimal number back into a precise or approximated fraction.

🧮

Enter your values and click Calculate

How It Works

The algorithm performs a brute-force search across all denominators d from 1 to maxDenominator. For each d, it computes the closest integer numerator n = Math.round(|decimal| × d), then measures the error as |decimal − n/d|. The denominator that produces the smallest error wins. After selecting the best numerator and denominator, the sign is restored for negative inputs. The fraction is then simplified by dividing both numerator and denominator by their Greatest Common Divisor, calculated using the Euclidean algorithm. If the simplified denominator equals 1 the result is displayed as a whole number. The residual approximation error — the original decimal minus the fraction value — is reported to eight decimal places so you can judge whether the match is exact or approximate.

Examples

Clean conversion
Converting 0.75 with a max denominator of 100.
Result: Perfectly matches 75/100, which simplifies to 3/4 with an error of 0.
Repeating decimal
Approximating 0.3333 with a max denominator of 10.
Result: Matches 3/9 (simplified to 1/3) with an extremely small error margin.
Tape measure conversion
Finding the closest 16th of an inch for the decimal 0.3125.
Result: Perfectly matches 5/16.

Frequently Asked Questions

Why do I need to set a maximum denominator?
Without a limit, any decimal like 0.123 can trivially be written as 123/1000. Capping the denominator gives you more practical, readable fractions like 1/8.
What does the approximation error mean?
Because we cap the denominator, the fraction might not perfectly equal your decimal. The error shows exactly how far off the fraction is from your true decimal value.
Can it handle whole numbers with decimals?
Yes! If you enter 1.5, the calculator will return 3/2 (an improper fraction) representing exactly 1 and 1/2.
How does simplification work?
The calculator divides both the top and bottom of the best match by their Greatest Common Divisor (GCD) to give you the cleanest possible representation.

Recommended Resources

Related Calculators