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}$

  • 2
    $\begingroup$ See this is RealDigits the replacement for what you want? $\endgroup$ – bobthechemist Oct 29 '13 at 13:54
  • $\begingroup$ i want to display the following number 3.13678989898989898989 and the 8989 part should be displayed as periodic $\endgroup$ – user2147674 Oct 29 '13 at 13:58
  • $\begingroup$ 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. $\endgroup$ – Yves Klett Oct 29 '13 at 14:03
  • $\begingroup$ books.google.at/… $\endgroup$ – user2147674 Oct 29 '13 at 14:04
  • 1
    $\begingroup$ @YvesKlett Apparently it was a function in the NumberTheory package that was in versions 6 and earlier. $\endgroup$ – 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

  • $\begingroup$ Nice - I started down this route, then realized I was just procrastinating from all the grading I have to do. $\endgroup$ – 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

  • 2
    $\begingroup$ You could use URLSave to install package. URLSave["library.wolfram.com/infocenter/MathSource/6773/…", FileNameJoin[{$UserBaseDirectory, "Applications", "ContinuedFractions.m"}]] and << ContinuedFractions` $\endgroup$ – halmir Oct 29 '13 at 15:03
  • $\begingroup$ 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. $\endgroup$ – 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.

  • $\begingroup$ Yes, RealDigits is the place to start. $\endgroup$ – 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]



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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