Extracting number of digits of terminating decimal

50 Views Asked by At

Let $x \in [0, 1)$ have a terminating decimal expansion. This means that $x$ almost certainly is not an integer and that a decimal expansion of $x$ eventually has an infinite string of only "0"s in it. Note that there are other decimal expansions of $x$ which do not terminate (but they should be nontrivially/non-"0"-ly repetitious); ignore these. Call the shortest terminating decimal expansion of $x$ "the canonical expansion of $x$".

This does require that $x \in \mathbb{Q}:$ the most-reduced denominator of $x$ is coprime to all primes other than, at most, some of the prime factors of the base (here: $10$).

How can one extract the number of digits in canonical expansion of $x$ (ignoring the infinite tail string of "0"s)?

For example, if we wanted the number of like digits in an integer $n$, then we could just calculate $\operatorname{floor}{(\log_{10}{(n)})} + 1$. I would like the same thing, but for integers divided by some power of the base.

Alternatively, extraction of the result of the power of the base which could form the denominator (not necessarily in most-reduced form) would work too, given that we know how to get that power via logarithm.

Ideally, the following constraints would be met: (1) Nothing like "just count them". (2) Nothing iterative. (3) No limits or infinite sequences, except implicitly in the definitions of common functions such as $\log$.

This should work for any base, although we are using decimal here.