开发者

Convert double string back to double

var doubleMaxValueString = double.MaxValue.ToString(CultureInfo.InvariantCulture);

and I want to convert it back to double, so I'm doing like this:

var doubleMaxValue = double.Parse(doubleMaxValueString, CultureInfo.InvariantCulture);

but it doesn't work...

how can I convert it back to double?

thanks!

开发者_StackOverflow

Edit: it throws: OverflowExceptionValue: was either too large or too small for a Double.

I'm using var because it's more practical =)


You can find good explanation here. Basically the problem is that while converting double to string we're rounding it up so it exceeds double.MaxValue. You can fix for example in this way:

var doubleMaxValueString = double.MaxValue.ToString("R", CultureInfo.InvariantCulture);
var doubleMaxValue = double.Parse(doubleMaxValueString, CultureInfo.InvariantCulture);

More information on "R" argument and why it helps may be found here on msdn

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜