How to tell when a fraction does not end?

222 Views Asked by At

Is there a way in math / programming to tell if a fraction (reciprocal in particular) does not end?

For example, 1/3 is 0.33 repeated, but 1/2 is just 0.5

Is there a way to find if 1/n for any natural number n is never ending?

Context: Writing a program and want to find out if I need to round 1/n (round in my way rather than whatever the machine does) before adding it to another digit.

E.g Since 1/3 is never ending, the machine will probably cut off some of the 3's at the end, and 1 + 1/3 = 1.33333. I want to be able to catch that 1/3 is never ending (or if 1/n is Not never ending) so that when I add a "never ending" number to 1, I can round it in my own way (i.e. I can round 0.3 up to 0.5, rather than the computers way of rounding never ending reciprocals / fractions).

1

There are 1 best solutions below

0
On

Hint: If a fraction in reduced form $\tfrac{a}{b}$ has a terminating decimal expansion, then $10^k\tfrac{a}{b}$ is an integer for sufficiently large $k$ (why is this?). Thus you can characterize the fractions with terminating decimal expansion solely in terms of $b$.