For a fraction in simplest form, the decimal terminates exactly when the denominator has no prime factors other than 2 and/or 5. This works because powers of 10 contain only factors 2 and 5.
If another prime factor remains, the decimal repeats. For example, 7/25=0.28 terminates, while 7/24=0.291666… recurs because 24=2³×3 contains a factor 3.
Digital tools can expose longer repeating patterns, but the denominator structure explains why the pattern terminates or recurs.