Long division by hand: multiply the remainder by 10, divide, write a digit, repeat. The decimal repeats as soon as a remainder repeats, because from then on the same digits come out again.
So store each remainder with the position where it first appeared:
1/6: rem 1 → digit 1 (rem 4) → digit 6 (rem 4) ← seen at position 1
→ "0.1(6)"
When the remainder becomes 0 the decimal terminates. When it repeats, wrap the digits from the first occurrence onward in parentheses. This detect a cycle by remembering states idea appears everywhere, from linked lists to games.