How do I write a decimal expansion of a rational number $a/b$ with only periodic part, e.g., given $1/7=0.14285714285714285714 \ldots$, I want just $0.142857$, the periodic part of $1/7$, to be displayed. I think I was able to do it sometime ago (with RealDigit or something similar), but now I forget what I did.


1 Answer 1


Straight from the docs:

For integers and rational numbers with terminating digit expansions, RealDigits[x] returns an ordinary list of digits. For rational numbers with non‐terminating digit expansions, it yields a list of the form {a1,a2,…,{b1,b2,…}} representing the digit sequence consisting of the ai followed by infinite cyclic repetitions of the bi

(* {{{1, 4, 2, 8, 5, 7}}, 0} *)

Try it online!

If you instead want to display real numbers in periodic form (with an overbar), use this answer.


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