Consider the repeating decimal number:
r = 3. = 3.141414...
I don't have to multiply this by an infinite power of 10. It turns out that I only need to multiply by a power of ten with the same magnitude as the length of the repeating part.
For this example the repeating sequence, , is n=2 digits long. So I multiply r by 10n
= 100 and get
100r = 314. = 314.141414...
The reason I've explicitly written equations for r and 100r, is that I want to subtract one equation from the other and make the messy repeating decimal disappear, leaving me with just an integer:
(100r - r) = 99r = 314. - 3. = 311
Then I solve for r.
r = 311/99
This is already reduced, since 311 and 99 are coprime, since 311=311 and 99=3*3*11.
Here's another example:
r = 0.
What is the length of the repeating part? The repeating sequence is 6 digits long, so multiply r by 106
, and get
1000000r = 142857
Then subtract these two equations and solve for r.
(1000000r - r) = 999999r = 142857
r = 142857/999999
Reducing this fraction is going to take some doing. Again I am using Octave's "factor()" and "gcd()" commands to help with the heavy lifting.
It turns out that:
r = 142857/999999 = (3*3*3*11*13*37)/(3*3*3*7*11*13*37) = 1/7
So what about those occasions when there is a sequence to the right of the decimal that does not repeat, followed by a sequence that does repeat? I think that is the the most general case, and the hardest decimal-to-fraction problem to solve. For example:
There are couple of ways to do this one. One way is to find 1000r, 100r, and then subtract these to get 900r.
1000r = 3456.
100r = 345.
900r = 3111
r = 3111/900 = 3*1037/3*300 = 1037/300