# Count Number of Digits in and Integer

This is a discussion on Count Number of Digits in and Integer within the C++ Programming forums, part of the General Programming Boards category; Does anyone know if it's possible to count the number of digits in an integer? One of my friends recommended ...

1. ## Count Number of Digits in and Integer

Does anyone know if it's possible to count the number of digits in an integer? One of my friends recommended log10 or something but I can't figure it out.

Redneon

2. the number of digits in a base 10 number is equal to the number of times you multiply 1 times 10 to get to the same length (plus one to account for the first digit). So essentially, log 10 is that number. your buddy is correct.

3. Here you go should work as you need
Code:
```
int number,  temp, print;
cin>>number;

print = 0;
while (temp != 0) {

temp = number % 10;
number = number / 10;
print++;
}
print = print -1; // reason for this below
cout<<print;```
i forget why but for some reason when usign a while loop. the loop will execute one time after the specified stopping point
IE it would count one more then needed.
try it without this and you'll see what i mean