How to count the number of digits of a floating number?

int numb_d(float n){
int nb=0;
while(((float)pow(10,nb))*n!=(int) (((float)pow(10,nb))*n)) nb++;
return nb;
}

This method should suffice.
It basicly always moves the comma one digit to the left and chops the digits after the comma of. And checks if choppign the digits of made a difference.

I hope I could help!

3 Likes