Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

I want to display a rational number in Mathematica in periodic style. PeriodicForm isn't working anymore. It worked in Mathematica 5 and now I'm using Mathematica 9.

I want to display the number $3.13678989898989898989\ldots$, where the repeating $89$ part should be displayed as $3.1367\overline{89}$

share|improve this question
See this is RealDigits the replacement for what you want? – bobthechemist Oct 29 '13 at 13:54
i want to display the following number 3.13678989898989898989 and the 8989 part should be displayed as periodic – user2147674 Oct 29 '13 at 13:58
Your question implies that there is/used to be some kind of solution or function (PeriodicForm?) which does not work anymore, which is a bit puzzling. – Yves Klett Oct 29 '13 at 14:03… – user2147674 Oct 29 '13 at 14:04
@YvesKlett Apparently it was a function in the NumberTheory package that was in versions 6 and earlier. – bobthechemist Oct 29 '13 at 14:05

You can always write your own version of PeriodicForm:

PeriodicForm[n_] := RealDigits[n] /. {{d___Integer, {i__Integer} ...}, l_Integer} :> 
    PeriodicForm[n, l, {d}, {i}]

Format[PeriodicForm[n_, l_, d_, i_]] ^:= Interpretation[Row[{
    FromDigits[d ~Take~ l] /. {} -> 0,
    Sequence @@ d ~Drop~ l, 
}] /. OverBar[0] :> Sequence[], n]

enter image description here

share|improve this answer
Nice - I started down this route, then realized I was just procrastinating from all the grading I have to do. – bobthechemist Oct 29 '13 at 16:12

To get PeriodicForm working in Mathematica 9 (and probably other versions after 6) you need to first download the obsolete package from the Wolfram Library Archive. Run the package, ignore the errors and have fun:


Mathematica graphics

share|improve this answer
You could use URLSave to install package. URLSave["…;, FileNameJoin[{$UserBaseDirectory, "Applications", "ContinuedFractions.m"}]] and << ContinuedFractions` – halmir Oct 29 '13 at 15:03
I wonder why this package is not integrated into the kernel. I suspect there are some subtleties that it cannot yet handle. Btw, you may want to show the FullForm of your example. – DavidC Oct 29 '13 at 15:48

Or, without the package, you can use

{{2, {7, 1, 4, 2, 8, 5}}, 1}

which shows the repeated decimal portion in the second (list) element of the answer. This tells you that the answer is 2 followed by repeating 714285. The final 1 is the exponent and allows the same representation to handle much larger or smaller numbers.

share|improve this answer
Yes, RealDigits is the place to start. – DavidC Oct 29 '13 at 15:22

Here you will find a discussion of issues related to the production of repeated decimals.

The code is reproduced below for convenience.

repeatingDecimal[n_Integer | n_Real] := n

Format[repeatingDecimal[q_Rational]] := 
Row@Flatten[{IntegerPart@q, ".", RealDigits@FractionalPart@q} /. {{nr___Integer, r_List: {}}, 
  pt_} :> {Table[0, {-pt}], nr, OverBar /@ r}]

repeatingDecimal[q_] + x_ ^:= q + x
repeatingDecimal[q_]*x_ ^:= q*x
repeatingDecimal[q_]^x_ ^:= q^x


n1 = 1; n2 = 15; ClearAll[i, k, r];
TableForm[Table[repeatingDecimal[i/j], {i, n1, n2}, {j, n1, n2}], 
TableHeadings -> {None, Table[("r")/k, {k, n1, n2}]}]


Simple arithmetic operations such as addition can be carried out on the repeating decimals.

a = repeatingDecimal[7/31];
b = repeatingDecimal[24/31];
Print["a = ", a]
Print["b = ", b]
Print["a + b = ", a, " + ", b, " = ", a + b]


share|improve this answer

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.