Possible Duplicate:
Dealing with accuracy problems in floating-point numbers
Code:
float flt = 78983636; // stores 78983632. as seen in debugger
flt = 79282056; // stores 79282056.
Why is it not able to accurately store 1st value, but able to for the 2nd value which is larger?
A typical 32-bit float has about 24 bits of integer precision. That you’re able to store your value precisely even though it’s larger is simply because it hits a sweet spot that looks proper as an integer, while the other one does not.
Specifically the number 79282056 is stored as 1.1813947 * 226, or 79282056.2526208. So it’s not exact, there’s some digits after the decimal point that you omitted.
You can use this converter to inspect the mantissa, sign and exponent used to store any floating-point number.