Every fraction converts to a decimal, but not every decimal is finite. 1/4 is a clean 0.25. 1/3 is 0.333... repeating forever. 1/7 is 0.142857142857... with a six-digit repeating cycle. Understanding why some fractions terminate and others repeat is useful for anyone working with numerical data, precision-sensitive calculations, or even database schema design.
The rule for terminating decimals
A fraction in lowest terms produces a terminating decimal if and only if the denominator's prime factors are limited to 2 and 5. That is it. If the denominator factors into only 2s and 5s (the prime factors of 10), the decimal terminates.
- 1/4 = 1/(2^2) -- terminates: 0.25
- 1/8 = 1/(2^3) -- terminates: 0.125
- 1/20 = 1/(2^2 * 5) -- terminates: 0.05
- 1/25 = 1/(5^2) -- terminates: 0.04
But introduce any other prime factor and you get a repeating decimal:
- 1/3 -- 3 is prime, not 2 or 5: repeats
- 1/6 = 1/(2 * 3) -- 3 is present: repeats (0.1666...)
- 1/7 -- 7 is prime, not 2 or 5: repeats
- 1/12 = 1/(2^2 * 3) -- 3 is present: repeats (0.08333...)
The long division connection
When you perform long division of 1 by 7, the remainder at each step can only be 0 through 6. If the remainder is ever 0, the decimal terminates. If it never reaches 0, you will eventually repeat a previous remainder, and from that point on the decimal repeats. Since there are only 6 possible non-zero remainders for division by 7, the repeating cycle is at most 6 digits long. For 1/7, the cycle is exactly 6: 142857.
This is a consequence of the pigeonhole principle. With a denominator of d, there are d-1 possible non-zero remainders. The repeating cycle length divides d-1 (by Fermat's little theorem when d is prime). So 1/7 has a cycle length that divides 6, and it happens to be exactly 6. 1/13 has a cycle length that divides 12, and it happens to be exactly 6 (0.076923076923...).
Practical implications in programming
When you store 1/3 as a floating-point number in most programming languages, you get 0.3333333333333333 -- 16 significant digits for a 64-bit double. This is a truncation of an infinite repeating decimal, and that tiny error matters in specific contexts.
// This fails because of floating-point representation
let sum = 0;
for (let i = 0; i < 3; i++) sum += 1/3;
console.log(sum === 1); // false
console.log(sum); // 0.9999999999999999
For financial calculations, this is why currencies are stored as integers (cents, not dollars) or using decimal libraries. $1.00 / 3 in floating-point gives you $0.3333333333333333, and three of those do not add back to $1.00.
Converting in your head
For common fractions, memorizing the decimal equivalents is faster than computing:
- 1/2 = 0.5
- 1/3 = 0.333...
- 1/4 = 0.25
- 1/5 = 0.2
- 1/6 = 0.1666...
- 1/7 = 0.142857...
- 1/8 = 0.125
- 1/9 = 0.111...
- 1/10 = 0.1
For more complex fractions, the mental math approach is to simplify first, then convert the simplified fraction. 15/24 simplifies to 5/8. 5/8 = 5 * 0.125 = 0.625. Much easier than dividing 15 by 24 in your head.
When you need exact conversion
For homework, engineering calculations, recipe conversions, or verifying your code's output, you sometimes need to convert a fraction to its exact decimal representation, including identifying the repeating portion. This is tedious to do by hand for anything beyond simple fractions.
I built a fraction-to-decimal converter at zovo.one/free-tools/fraction-to-decimal-calculator that converts any fraction to its decimal equivalent, clearly showing which digits repeat. Enter a fraction like 22/7 and get 3.142857 with the repeating block identified. Handles improper fractions and mixed numbers as well.
I'm Michael Lip. I build free developer tools at zovo.one. 500+ tools, all private, all free.
Top comments (0)