Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We know $\frac{1}{81}$ gives us $0.\overline{0123456790}$

How do we create a recurrent decimal with the property of repeating:


a) Is there a method to construct such a number?

b) Is there a solution?

c) Is the solution in $\mathbb{Q}$?

According with this Wikipedia page: One could get this number by applying this series. Supppose:

$M=123456789$, $x=10^{10}$, then $0.\overline{0123456789}= \frac{M}{x}\cdot$ $\sum$ ${(10^{-9})}^k$ $=\frac{M}{x}\cdot\frac{1}{1-10^{-9}}$ $=\frac{M}{9999999990}$

Unless my calculator is crazy, this is giving me $0.012345679$, not the expected number. Although the example of wikipedia works fine with $0.\overline{123}$.

Some help I got from mathoverflow site was that the equation is: $\frac{M}{1-10^{-10}}$. Well, that does not work either.

So, just to get rid of the gnome calculator rounding problem, running a simple program written in C with very large precision (long double) I get this result:

#include <stdio.h> 
int main(void)
  long double b;
  printf("%.40Lf\n", b); 

Result: $0.0123456789123456787266031042804570461158$

Maybe it is still a matter of rounding problem, but I doubt that...

Please someone?




Thanks for the answers. After understanding the problem I realize that long double is not sufficient. (float is 7 digits:32 bits, double is 15 digits:64 bits and long double is 19 digits:80 bits - although the compiler align the memory to 128 bits)

Using the wrong program above I should get $0.0\overline{123456789}$ instead of $0.\overline{0123456789}$. Using the denominator as $9999999999$ I must get the correct answer. So I tried to teach my computer how to divide:

#include <stdio.h>
int main(void)
    int i;
    long int n, d, q, r;
        printf("%ld", q);
share|cite|improve this question
Change the C program to assign b=123456789.0/9999999999.0; Note the integral value of the denominator should end in a 9, not a 0. – Brandon Carter Mar 29 '11 at 2:53
Thanks @Brandon, but only this was not sufficient. Look at the edition. – Dr Beco Mar 29 '11 at 4:03
Now I get any precision I want, just change while(i<PREC). Output with 100: 0,012345678901234567890123456789012345678901234567890123456789012345678901234567‌​8901234567890123456789 – Dr Beco Mar 29 '11 at 4:07
TIP Use one of the many freely available mathematics systems with multiple precision arithmetic instead of wasting your time rolling your own, e.g.[123456789/%2810^10-1%29,40] – Bill Dubuque Mar 29 '11 at 4:31
@Bill Wow! I'm astonished! Thank you very much for this great tip. – Dr Beco Mar 29 '11 at 5:15
up vote 3 down vote accepted

Suppose you want to have a number $x$ whose decimal expansion is $0.a_1a_2\cdots a_ka_1a_2\cdots a_k\cdots$. That is it has a period of length $k$, with digits $a_1$, $a_2,\ldots,a_k$.

Let $n = a_1a_2\cdots a_k$ be the integer given by the digits of the period. Then $$\begin{align*} \frac{n}{10^{k}} &= 0.a_1a_2\cdots a_k\\ \frac{n}{10^{2k}} &= 0.\underbrace{0\cdots0}_{k\text{ zeros}}a_1a_2\cdots a_k\\ \frac{n}{10^{3k}} &= 0.\underbrace{0\cdots0}_{2k\text{ zeros}}a_1a_2\cdots a_k\\ &\vdots \end{align*}$$ So the number you want is $$\sum_{r=1}^{\infty}\frac{n}{10^{rk}} = n\sum_{r=1}^{\infty}\frac{1}{(10^k)^r} = n\left(\frac{\quad\frac{1}{10^k}\quad}{1 - \frac{1}{10^k}}\right) = n\left(\frac{10^k}{10^k(10^k - 1)}\right) = \frac{n}{10^k-1}.$$ Since $10^k$ is a $1$ followed by $k$ zeros, then $10^k-1$ is $k$ 9s. So the fraction with the decimal expansion $$0.a_1a_2\cdots a_ka_1a_2\cdots a_k\cdots$$ is none other than $$\frac{a_1a_2\cdots a_k}{99\cdots 9}.$$

Thus, $0.575757\cdots$ is given by $\frac{57}{99}$. $0.837168371683716\cdots$ is given by $\frac{83716}{99999}$, etc.

If you have some decimals before the repetition begins, e.g., $x=2.385858585\cdots$, then first multiply by a suitable power of $10$, in this case $10x = 23.858585\cdots = 23 + 0.858585\cdots$, so $10x = 23 + \frac{85}{99}$, hence $ x= \frac{23}{10}+\frac{85}{990}$, and simple fraction addition gives you the fraction you want.

And, yes, there is always a solution and it is always a rational.

share|cite|improve this answer
Thanks @Arturo for this very explanatory solution. Now I got the correct result, with any precision I want, just changing the "while" with the new program (see edition). – Dr Beco Mar 29 '11 at 4:06

It's simple: $\rm\displaystyle\ x\ =\ 0.\overline{0123456789}\ \ \Rightarrow\ \ 10^{10}\ x\ =\ 123456789\ +\ x\ \ \Rightarrow\ \ x\ =\ \frac{123456789}{10^{10} - 1}$

Note that the last digit of $\rm\ 10^{10} - 1\ $ is $\:9\:,$ not $\:0\:,$ which explains the error in your program.

share|cite|improve this answer
Thanks @Bill, you corrected the formula, but the problem was long double rounding it. – Dr Beco Mar 29 '11 at 4:04
@Dr Beco: I assumed the rest would be easy once you had the correct formula. – Bill Dubuque Mar 29 '11 at 4:27

When you say "double" in C how many places is that?

I tried it in Maple...


Digits := 40;
0.01234567891234567891234567891234567891235 `

share|cite|improve this answer
Float is 7 digits (32 bits), Double is 15 digits (64 bits) and Long Double is 19 digits (only 80 digits used, but the alignment make it 128 bits). This long double number "0.012345678901234568431" loses precision in the 18 digit, as expected... My program didn't work because of that! Thanks. – Dr Beco Mar 29 '11 at 3:55
BTW, what is maple? A language? Do you have any link I could spy on it? Thanks – Dr Beco Mar 29 '11 at 4:10

You said:

$M=123456789$, $x=10^{10}$, then $0.\overline{0123456789}= \frac{M}{x}\cdot$ $\sum$ ${(10^{-9})}^k$ $=\frac{M}{x}\cdot\frac{1}{1-10^{-9}}$ $=\frac{M}{9999999990}$

but since the block of repeating digits is 10 digits long, the summation term should be $\sum{(10^{-10})}^k$, so that $$0.\overline{0123456789}=\frac{M}{x}\cdot\sum{(10^{-10})}^k=\frac{M}{x}\cdot\frac{1}{1-10^{-10}}=\frac{M}{9999999999}$$ and $$\frac{M}{9999999999}=\frac{123456789}{9999999999}=\frac{13717421}{1111111111}.$$

share|cite|improve this answer
Thanks! Using your last fraction, the long double can give at least 2 repetitions before lose precision: 0.0123456789 0123456789 0470 – Dr Beco Mar 29 '11 at 4:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.