How to obtain the number of digits of a float or integer variable?

How to obtain the number of digits of a float or integer variable?

You can recursively while loop divide an int by 10, compare to 0 and eventually you’ll arrive at a value. Or simply:

321942-screenshot-2020-11-13-161554.jpg

…instead.


It’s a bit more complicated for a float because of [the precision errors][2] but for as long as you know how many fractional digits you need, you can also:

1 Like