3

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

Sierra
  • 31
  • Multiplie 600,045 by 1000 – hyperkahler Jul 03 '15 at 18:29
  • 2
    @Arteom: Which would imply you already know the number of digits :) – user251257 Jul 03 '15 at 18:46
  • You need to be more specific. If you are talking about floating point numbers on computers, most systems provide specific functions for this purpose. If you are talking about real numbers as in math, I am not aware of any algorithm that terminates for every input. – user251257 Jul 03 '15 at 19:09

2 Answers2

2

Hint

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

ajotatxe
  • 65,084
1

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...