# Thread: counting how long an integer is

1. ## counting how long an integer is

Hi there

is there anyway of counting how long an integer is, using something like strlen, since I dont think that works with integers

e.g. 100000000

is 9 characters long

would appreciate any help

2. Convert it to a string and use strlen()

By the way, the example number you gave was too big to be a regular int. Make it a long int.

for ints, use itoa(), for longs, ltoa(). The usage is:

itoa(num, string, 10);

where the last parameter is always "10" if you are using the base-10 (normal) number system.

3. By the way, the example number you gave was too big to be a regular int.
That depends on the o/s. 32 bit o/s's will use 32 bit ints, allowing signed values up to 2147483647.

4. Here's another way. Credit goes to someone who posted this on the old board.
Code:
```int numlen(int n)
{
//get the length of a integer this will work for the length of longs also
//but this function will not work with floats or doubles because of the decimal point.
return (log10(n)+1);
}```