Decimal to Fraction Calculator
Convert a decimal number back into a precise or approximated fraction.
Enter your values and click Calculate
Fractions appear constantly in the physical world even when digital tools give you a decimal result. Carpenters need measurements in sixteenths of an inch (max denominator 16), cooks work in thirds and quarters (max denominator 8), and pharmacists deal in tenths and hundredths. When a measuring device returns 0.3125 inches, knowing that equals exactly 5/16 is far more useful than the raw decimal. This calculator tests every denominator from 1 up to your chosen maximum, selects the fraction with the smallest approximation error, and simplifies it using the Greatest Common Divisor. It works for values below zero, above 1, and exactly 0, and reports the residual error so you know how close the approximation is.
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.