So, I am really confused about the number of decimals after the floating point in a float type variable. In the book that I am reading, it says that the float variable can include up to 6 decimals after the floating point. But the problem is, in the internet it says that a float variable can save up to 7digits after the decimal point. Who is right and what is the number of decimals that a float variable can save after the decimal point?
Asked
Active
Viewed 45 times
0
-
In short: A 32-bit FP variable (type `float`) saves exactly 24 significant figures in binary (base-2), while a 64-bit FP (type `double`) saves exactly 53. – iBug Mar 17 '21 at 16:14
-
Most systems today uses [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754) format for their floating point values. You might want to read up on it a little. – Some programmer dude Mar 17 '21 at 16:17
-
That depends on how many decimal digits are *before* the decimal point. It is the number of *significant* digits that counts, and because the value is stored in binary it is not an exact number of decimal digits. – Weather Vane Mar 17 '21 at 16:22
-
A simple test: `y = ((float)(1 + 1.0e-8) - 1.0)*1.0e8;` gives `y = 0.0` instead of `1.0` – Damien Mar 17 '21 at 16:27
-
[Measuring binary floating-point formats in decimal digits is misguided.](https://stackoverflow.com/a/61614323/298225) Because 24 bits provide a precision around 1 in 10^7.2, converting any six-significant-digit decimal number in bounds to IEEE-754 binary32 and back to a six-digit number with correct rounding to nearest in bound directions produces the original number. It does not guarantee seven because the powers ten vary relative to the powers of two, in a sense preventing the full use of the precision to preserve decimal digits. – Eric Postpischil Mar 17 '21 at 16:43