# Finding # of digits in an integer

• 10-15-2005
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?

• 10-15-2005
Thantos
ceiling ( log(num) / log(10) )
• 10-15-2005
Quote:

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?
• 10-15-2005
Thantos
Quote:

Is this method fast?
Depends
Quote:

Is there a faster one?
Probably
Quote:

Would this method work if x is a multiple of 10?
Try it and see
• 10-16-2005
Salem
> 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?