sc*****@gmail.com wrote:
Hello,
i have the following problem in our project:
If I try to parse a string value with the following line
double x = double.Parse("39.95238", CultureInfo.InvariantCulture);
x contains 39.9523799999.... instead of the correct one.
What could be the reason for that?
Thanks in advance
Chris
The reason would be that floating point types are not accurate, and
store an approximation of the value. You'll find that you will
frequently notice two variations of this, either slightly lower
(.99999999) or slightly higher (.0000000001).
Try using Decimal, or just format the value for output to round to a
specific number of digits.
--
Lasse Vågsæther Karlsen
mailto:la***@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3