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!
开发者_StackOverflowEdit: 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
精彩评论