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

I think there’s a basic confusion in the question. One thing is the floating point number as it’s stored, and another is how many decimal places are printed. However you’ve viewed it, it’s been converted to a string and something has chosen how many decimal places to show. Suppose you set the value to √2 or PI, we know there are infinite decimal places, but we don’t usually print them all. (Depending on the storage type only a certain number can be relied on to be correct.)

You could avoid calling it a string, and calculate each decimal digit separately, but you still have to chose arbitrarily when to stop.