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

VariableDescriptionDefault
decimal_valDecimal Value0.375
raw_numeratorDerived value= round(decimal_val * 10000)calculated
raw_denominatorDerived value= 10000calculated
common_factorDerived 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
  1. 010.375 × 10000 = 3750
  2. 02Fraction = 3750/10000
  3. 03GCD(3750, 10000) = 1250
  4. 04Simplified: 3750/1250 = 3, 10000/1250 = 8
  5. 05Result: 3/8

Ready to run the numbers?

Open Decimal to Fraction Calculator