Hello,
Problem is caused by rounding in the default implementation of ToString
method. In the example you gave, method creates a string presentation of a
number rounded to a value that is larger than the largest double number
allowed. So, when you try to parse that string, it throws an exception. You
can check this comparing following two outputs:
Console.WriteLi ne(double.MaxVa lue.ToString()) ;
Console.WriteLi ne(double.MaxVa lue.ToString("E 20"));
Therefore this code:
double.Parse(do uble.MaxValue.T oString("E20"))
will not throw the exception.
Regards,
Julijan
"Markus Kling" <Ma*********@di scussions.micro soft.com> wrote in message
news:26******** *************** ***********@mic rosoft.com...
"double.Parse(d ouble.MaxValue. ToString())" yields the following Exception:
Value was either too large or too small for a Double.
at System.Number.P arseDouble(Stri ng value, NumberStyles options,
NumberFormat
Info numfmt)
at System.Double.P arse(String s, NumberStyles style, NumberFormatInf o
info) at System.Double.P arse(String s)
...
Even double.Parse((d ouble.MaxValue -1).ToString()) states the same error
message.
That's completly illogical. Is this an error or my misunderstandin g?