How can I prove that all rational numbers are either terminating decimal or repeating decimal numerals?

I am trying to figure out how to prove that all rational numbers are either terminating decimal or repeating decimal numerals, but I am having a great difficulty in doing so. Any help will be greatly appreciated.


Hint$\ $ Consider what it means for a real $\rm\ 0 < \alpha < 1\ $ to have a periodic decimal expansion:

$$\begin{array}{rrl} &\alpha\!\!\! &\rm =\,\ 0\:.\overbrace{a_1a_2\cdots a_n^{\phantom{l}}}^{\textstyle a}\ \overbrace{\overline{c_1c_2\cdots c_k}}^{\textstyle \overline c}\ \ \text{ in radix } 10\\[.2em] \iff& \beta \!\!&\!:= \rm 10^n\, \alpha\! -\! a = 0\:.\overline{c_1c_2\cdots c_k}\\[.2em] \iff& 10^k\: \beta \!\!&=\ \rm c + \beta\\[.2em] \iff& (10^k-1)\ \beta \!\!&=\ \rm c\\[.2em] \iff&\!\!\!\! \rm (10^k-1)\ 10^n\: \alpha \!\!&\in\ \Bbb Z \end{array}\qquad$$

Thus to show that a rational $\rm\,\alpha\,$ has such a periodic expansion, it suffices to find $\rm\,k,n\,$ as above, i.e. so that $\rm\,(10^k-1)\,10^n\,$ serves as a denominator for $\rm\,\alpha.\,$ Put $\rm\,\alpha\, = a/b,\,$ and $\rm\, b = 2^i\,5^j\,d,\,$ where $\rm\,2,5\,\nmid d\,.\,$ Choosing $\rm\,n\, >\, i,\,j\,$ ensures that $\rm\,10^n\,\alpha\,$ has no factors of $\rm\,2\,$ or $\rm\,5\,$ in its denominator. Hence it remains to find some $\rm\,k\,$ such that $\rm\,10^k-1\,$ will cancel the remaining factor of $\rm\,d\,$ in the denominator, i.e. such that $\rm\,d\,|\,10^k-1\,,\,$ or $\rm\,10^k\equiv 1\pmod{d}\,.\,$ Since $\rm\,10\,$ is coprime to $\rm\,d,\,$ by the Euler-Fermat theorem we may choose $\rm\,k = \phi(d),\,$ which completes the proof sketch. For the converse, see this answer.


Recall that in long division, one gets a remainder at each step: $$ \begin{array} & & & 0 & . & 2 & 2 & 7 & 2 \\ \hline 22 & ) & 5&.&0&0&0&0&0 \\ & & 4 & & 4 \\ & & & & 6 & 0 & \leftarrow \\ & & & & 4 & 4 \\ & & & & 1 & 6 & 0 \\ & & & & 1 & 5 & 4 \\ & & & & & & 6 & 0 & \leftarrow & \text{repeating}\\ \end{array} $$ 6 is a remainder. The next remainder is 16. Then the next is 6. This brings us back to where we were at an earlier step: Dividing 60 by 22. We have to get the same answer we got the previous time. Hence we have repetition of "27". The answer is $0.2272727\overline{27}\ldots$, where "27" keeps repeating.

The question then is: Why must we always return to a remainder that we saw earlier? The answer is that the only possible remainders are $0, 1, 2, 3, \ldots, 21$ (if $22$ is what we're dividing by) and there are only finitely many. If we get 0, the process terminates. If we never get 0, we have only 21 possibilities, so we can go at most 21 steps without seeing one that we've seen before. As soon as we get one that we've seen before, the repetition begins.

A related question worth asking is how you know that every repeating decimal corresponds to a rational number. E.g., if you're handed $0.2272727\overline{27}\ldots$ with "27" repeating forever, how do you figure out that it's exactly $5/22$? There's a simple algorithm for that too.