Decimal to Fraction Calculator Formula
Understand the math behind the decimal to fraction calculator. Each variable explained with a worked example.
Formulas Used
Numerator
numerator = round(decimal_val * 10000) / gcd(abs(round(decimal_val * 10000)), 10000)Denominator
denominator = 10000 / gcd(abs(round(decimal_val * 10000)), 10000)Verification
verification = (round(decimal_val * 10000) / gcd(abs(round(decimal_val * 10000)), 10000)) / (10000 / gcd(abs(round(decimal_val * 10000)), 10000))Variables
| Variable | Description | Default |
|---|---|---|
decimal_val | Decimal Value | 0.375 |
raw_numerator | Derived value= round(decimal_val * 10000) | calculated |
raw_denominator | Derived value= 10000 | calculated |
common_factor | Derived value= gcd(abs(round(decimal_val * 10000)), 10000) | calculated |
How It Works
How to Convert a Decimal to a Fraction
Method
1. Write the decimal as a fraction over a power of 10 (e.g., 0.375 = 375/1000) 2. Simplify by dividing both numerator and denominator by their GCD 3. For example: 375/1000 → GCD(375, 1000) = 125 → 375/125 = 3, 1000/125 = 8 → 3/8
This calculator uses a denominator of 10,000 for precision and then simplifies.
Worked Example
Convert 0.375 to a fraction.
decimal_val = 0.375
- 010.375 × 10000 = 3750
- 02Fraction = 3750/10000
- 03GCD(3750, 10000) = 1250
- 04Simplified: 3750/1250 = 3, 10000/1250 = 8
- 05Result: 3/8
Ready to run the numbers?
Open Decimal to Fraction Calculator