TITLE: Why must the decimal representation of a rational number in any base always either terminate or repeat?
QUESTION [6 upvotes]: Wikipedia makes the following statement about rational numbers.

The decimal expansion of a rational number always either terminates
  after a finite number of digits or begins to repeat the same finite
  sequence of digits over and over. Moreover, any repeating or
  terminating decimal represents a rational number. These statements
  hold true not just for base 10, but also for binary, hexadecimal, or
  any other integer base.

Can anyone shed intuition and/or a mathematical proof for why this is true?

REPLY [3 votes]: Let $a\operatorname{div}b$ be the integer part of division of $a$ by $b$. (Example: $7\operatorname{div}5 = 1$)
Let $a\bmod b$ be the remainder part of division of $a$ by $b$. (Example: $7\bmod 5 = 2$)
Suppose $a < b$. When you perform division what basically you do is these steps:
$$\begin{align}
& i_1 = (10\cdot a)\operatorname{div}b \ \ \ \text{and}\ \ \ r_1 = (10\cdot a)\bmod b \\ 
& i_2 = (10\cdot r_1)\operatorname{div}b \ \ \ \text{and}\ \ \ r_2 = (10\cdot r_1)\bmod b \\
& i_3 = (10\cdot r_2)\operatorname{div}b \ \ \ \text{and}\ \ \ r_3 = (10\cdot r_2)\bmod b \\ 
& i_4 = (10\cdot r_3)\operatorname{div}b \ \ \ \text{and}\ \ \ r_4 = (10\cdot r_3)\bmod b \\ 
& \quad\vdots
\end{align}$$
If division result digits terminates, then division result is: $0.i_1 i_2 i_3\ldots i_k$, where $k$ is some finite number. This happens because $10\cdot r_k$ is divisible by $b$.
If division result digits do not terminate, then division result is: $0.i_1 i_2\ldots i_k i_1 i_2\ldots i_k i_1 i_2\ldots i_k\ldots$, where $k$ is some finite number. This happens because non of $10\cdot r_1, 10\cdot r_2, \ldots, 10\cdot r_k$ is divisible by $b$, but since $b$ is finite number remainders bus appear more than once and therefore when it appears for the second time digits start to repeat.