# Thread: Finding # of digits in an integer

1. ## Finding # of digits in an integer

I'm writing a little thing to find prime numbers.
I'm looking for a really fast method.
I'm a very early beginner.
I have thought of dividing the int by 10 until it equals 0.
I have thought of converting the int into a string and finding length.
Is there a faster way?

2. ceiling ( log(num) / log(10) )

3. Originally Posted by Thantos
ceiling ( log(num) / log(10) )
Thanks.
Is this method fast?
Is there a faster one?
Would this method work if x is a multiple of 10?

4. Is this method fast?
Depends
Is there a faster one?
Probably
Would this method work if x is a multiple of 10?
Try it and see

5. > I have thought of dividing the int by 10 until it equals 0.
Would work

> I have thought of converting the int into a string and finding length.
Also would work.

> Is there a faster way?
Consider
Code:
```while ( x >= 10000 ) { x /= 10000 ; count += 4; }
while ( x >= 10 ) { x /= 10 ; count += 1; }```
Also, are you generating a whole series of numbers in a for loop, and trying to find the length of each?
Say for ( i = 1 ; i < 100000000 ; i++ ) kind of thing?