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

I think you’re assuming precision (or number of significant digits) and number of decimal places are the same thing. Suppose it only stores 7 digits, that might be 1.234567 or 0.01234567 or anything similar between +/- 10E38. This page has a good explanation of float and double and it says that Java uses IEEE 754 Floating-Point. Now we know that, we can play with this floating point converter.

Yes, for more precision there is the double type.

You can control how Processing prints e.g. try println(String.format("%12.10f", PI));

Different CPUs may have different characteristics, but we trust that whoever wrote the compiler knew about that and programmed accordingly. Some years ago it was common to have a CPU and separate Floating-Point Processor. Or maybe for economy the FPP was missing, so the programs used floating point emulation code.

1 Like