Finding number of digits of decimal number

2.3k Views Asked by At

I'm looking for a way to calculate the number of digits in a decimal number, such as $600.045$.

I'm aware of the $1+\mathrm{int}(\log(x))$ formula for finding number of digits of an integer, but this doesn't work for non-whole numbers.

Can anyone think of a way to do this?

If it helps, I'm trying to accurately find square root on a TI-84 using the Babylonian method, and to do this I need to know significant digits

2

There are 2 best solutions below

0
On

Hint

The number of digits of $x$ after the point is the least integer $n$ such that $10^nx$ is integer.

0
On

I needed the same algorithm recently. I have made a program that counts the digits in the decimal expansion of the number; from there you can add 1+int(log(N)). The input is in Ans.

prgmDIG
Ans->A
0->N
While 10^(N)A≠int(A10^(N
N+1->N
End
N

To use the function, you can type your number:prgmDIG.

What the code does is simple: starting at 0, N is incremented until 10^(N)A is an integer, basically (no pun intended) what @ajotatxe said. Hope it helps!

edit

As per the babylonian method, I am lost; I thought that was used for computing square roots...