get digits of int c++ code example
Example 1: count digits c++
template <class T>
T countDigits(T number)
{
return T(log10(number) + 1);
}
//If the number is very large, use string
Example 2: c++ get digits of integer
int iNums = 12345;
int iNumsSize = 5;
for (int i=iNumsSize-1; i>=0; i--) {
int y = pow(10, i);
int z = iNums/y;
int x2 = iNums / (y * 10);
printf("%d-",z - x2*10 );
}