I'm trying to count the number of digits in fractional part of double, but something is going wrong and I getting infinite loop:
double pi = 3.141592;
int counter = 0;
for (; pi != int(pi); ++counter)
pi *= 10;
cout << counter << endl;
I'v just read about this problem, however I can't find a good solution. Is there really no better way than convert a number to string and count chars? I suppose there's more correct method.