float.Parse("534818068")
returns: 534818080
I understand that there are many complications with float and decimal values. But maybe someone could explain this behaviour to me.
Thanks!
float.Parse("534818068")
returns: 534818080
I understand that there are many complications with float and decimal values. But maybe someone could explain this behaviour to me.
Thanks!
Floating point numbers have a relative precision, i.e. something like 7 or 8 digits. So only the first 7 or 8 digits are correct, independent of the actual total size of the number.
Floating point numbers are stored internally using the IEEE 754 standard (a sign, a biased exponent and a fraction).
float
numbers are stored with a 32 bits representation, which means they will have a precision of 7 digits.
On the other hand, double
are stored with a 64 bits representation, thus having 15-16 digits (source).
Which is why you shouldn't usually compare floats for equality for instance.