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.
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 theai
followed by infinite cyclic repetitions of thebi
.»
Print@RealDigits[1/7]
(* {{{1, 4, 2, 8, 5, 7}}, 0} *)
If you instead want to display real numbers in periodic form (with an overbar), use this answer.