I'm trying to create an exact decimal numeric type. I was storing it as a rational p/q
where q
is always as power of 10.
Now if I try to divide one of these numbers, I need to see if the result is representable as a finite decimal expansion. For example 10.2 / 80 => 0.1275
is okay, but 10 / 3 = 3.333...
is not okay.
It boils down to looking at an integer q
and asking: is there an integer m
such that:
q * m = 10 ^ n (q, m, n are all integers)
I can write a loop to search for it, testing n=0,1,2,3,...? But is there a more direct way? I don't know how to solve that little equation algebraiclly.