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.
$$
\frac{1}{(1000-1)^2}
=\frac{10^{-6}}{(1-\frac{1}{1000})^2}
=\frac{10^{-6}}{(1-x)^2}
=10^{-6}\left(\sum_{n=0}^{\infty}x^n\right)^2
=10^{-6}\sum_{n=1}^{\infty}nx^{n-1}
$$
for $x=.001$, which has no carries in its decimal expansion for $n<1000$. Thus the first $1000$ triplets ($3000$ digits after the decimal place) will be $0.000\;001\;002\;003\;\dots\;996\;997\;999\;000$, which brings us up to the first digit which receives a carry.
If you want to see it without the scientific notation, add one before formatting. In sage:
(1+(10^3-1)^(-2)).n(digits=3001) # ignore the leading one in the output!
or in scientific notation:
((10^3-1)^(-2)).n(digits=3001) # note the e-6 at the end, meaning times 10^{-6}
As to the formula above, it can be derived by differentiation:
$$
\left(\sum_{n=0}^{\infty}x^n\right)^2
=(1-x)^{-2}
=\frac{d}{dx}(1-x)^{-1}
=\frac{d}{dx}\left(\sum_{n=0}^{\infty}x^n\right)
=\sum_{n=1}^{\infty}nx^{n-1}
\qquad\text{for}
\qquad|x|<1
$$
Best Answer
Given a fraction $p/q$, first get it into its lowest terms (so that $p$ and $q$ have no common factor). Then, if $q$ is of the form $2^a5^b$ for integers $a,b$, its decimal expansion has max$(a,b)$ digits after the decimal point. If it's not of this form, its decimal expansion is non-terminating (but repeating).