Re: Converting Long to Float: Values not Matching



Z wrote:
I am getting:

3250051236
3.25005133E9

I tried with multiple numbers but still the values are not equal. What
am I missing?

Thanks,

Floats have limited precision. Your number is larger than the number of the precision.

Internally, numbers are represented as a number (the mantissa) multiplied by some power of 2; your number cannot be exactly represented to the precision that the mantissa has, so it lops off a few bits at the end, giving you a moderately close but not exact approximation.
--
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
.