开发者

Wrong value with double.Parse(string)

I'm trying to convert a string to a double value in .Net 3.5. Quite easy so far with

double.Parse(value);

My problem is that values with exponential tags are not right converted. Example:

double value = double.Parse("8.493151E-2");

The value should be = 0.0893151 right? But it isn't! The value is = 84931.51!!!

How can that be? I'm totally confused!

I read the reference in the msdn library and it confirms that values like "8.493151E-2" are supported. I also 开发者_如何学Gotried overloads of double.Parse() with NumberStyles, but no success.

Please help!


It works for me:

double.Parse("8.493151E-2");  
0.08493151

You're probably running in a locale that uses , for the decimal separator and . for the thousands separator.
Therefore, it's being treated as 8,493,151E-2, which is in fact equivalent to 84,931.51.

Change it to

double value = double.Parse("8.493151E-2", CultureInfo.InvariantCulture);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜