10. Decimal representation of rational numbers
The decimal representation of a rational number $m/n$ is obtainable by dividing $n$ into $m$ using long division. Thus $9/5=1.8$ and $1/3=0.333\ldots$
A decimal representation which is all 0’s after a certain point has to be the decimal representation of a rational number. For example, $1.853$ is the rational number $1853/10^{3}$. On the other hand, the example of $1/3$ shows that the decimal representation of a rational number can go on forever.
The following fact is useful: If the decimal representation of a number $n$ starts repeating in blocks after a certain point, then $n$ is rational. For example, $1/7=0.\overline{142857}$ with the block 142857 repeated forever.
The following theorem says exactly which rational number is represented by a decimal representation with a repeating block of consecutive digits:
10.1 Theorem
If $n=0.bbb\ldots$, where $b$ is a block of $k$ consecutive digits, then $n=b/(10^{k}-1)$.
10.1.1 Example $0.\overline{13}$ is $13/99$. As another example, the theorem says that $0.\overline{3}$ is $3/9$, which of course is correct.
10.1.2 Exercise Give the exact rational value in lowest terms of $5.\overline{1}$, $4.\overline{36}$, and $4.1\overline{36}$. (Answer on page 243.)
10.1.3 Remark Theorem 10.1 says that if the decimal representation of a real number repeats in blocks then the number is rational, and moreover it tells you how to calculate it. Actually, the reverse is true, too: the decimal representation of a rational number must repeat in blocks after a certain point.
You can see why this is true by thinking about the process of long division: Suppose you have gone far enough that you have used up all the digits in the dividend (so all further digits are zero). Then, if you get a certain remainder in the quotient twice, the process necessarily repeats the second time what it did the first time.
10.2 Representations in general
It is important to distinguish between a mathematical object such as a number and its representation, for example its decimal representation or (in the case of a rational number) its representation as a fraction of integers. Thus $9/5, 27/15$ and $1.8$ all represent the same number which is in fact a rational number. We will return to this idea several times, for example in Section 17.1.3 and in Section 66.8.
10.3 Types of numbers in Mathematica
Mathematica knows about integers, rational numbers and real numbers. It treats a number with no decimal point as an integer, and an explicit fraction, for example 6/14, as a rational number. If the number has a decimal point, it is always regarded as real number.
IntegerQ[n] returns True if $n$ is represented as an integer in the sense just described. Thus IntegerQ[3] returns True, but IntegerQ[3.0] returns False.
Mathematica will store a number given as the fraction of two integers as a rational number in lowest terms. For example, if you type 6/14, you will get 3/7 as the answer. It will return the sum, product, difference and quotient of rational numbers as rational numbers, too. Try typing 3/7+5/6 or (3/7)/(5/6), for example.
The function that gives you the decimal representation of a number is N. For example, N[3/7] gives 0.4285714285714286. You may give a second input to N that gives the number of decimal digits that you want. Thus N[3/7,20] gives
0.42857142857142857143
You can invoke N by typing //N after an expression, too. For example, instead of typing N[3/7+5/4], you can type 3/7 + 5/4 //N.
Pages 14–15 of the book (PDF).