468,161 Members | 1,952 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,161 developers. It's quick & easy.

convert double.MinValue to string and back


Why does this not work, and how should i do this convert in stead:

string x = double.MinValue.ToString();
double y = Convert.ToDouble(x);

i get this exception:
An unhandled exception of type 'System.OverflowException' occurred in mscorlib.dll
Additional information: Value was either too large or too small for a Double.

Pascal
Nov 15 '05 #1
2 4712
Hello Pascal,

Because
string x = double.MinValue.ToString();
rounds x to -1.79769313486232E+308, whereas the actual minimum value
is -1.7976931348623157E+308. This is a bit higher, so you get the overflow
error when you try to convert it back.

Try using
string x = double.MinValue.ToString("R");
to convert using the 'round trip' (no rounding) format instead.

I hope that helps.
"Pascal" <pa****@unknown.com> wrote in message
news:c1**********@reader08.wxs.nl...

Why does this not work, and how should i do this convert in stead:

string x = double.MinValue.ToString();
double y = Convert.ToDouble(x);

i get this exception:
An unhandled exception of type 'System.OverflowException' occurred in mscorlib.dll Additional information: Value was either too large or too small for a Double.
Pascal

Nov 15 '05 #2
yes it helped, thanks!

"Pascal" <pa****@unknown.com> wrote in message
news:c1**********@reader08.wxs.nl...

Why does this not work, and how should i do this convert in stead:

string x = double.MinValue.ToString();
double y = Convert.ToDouble(x);

i get this exception:
An unhandled exception of type 'System.OverflowException' occurred in mscorlib.dll Additional information: Value was either too large or too small for a Double.
Pascal

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by msnews.microsoft.com | last post: by
2 posts views Thread by Laurence | last post: by
17 posts views Thread by David Scemama | last post: by
3 posts views Thread by mrajanikrishna | last post: by
9 posts views Thread by =?Utf-8?B?Qnlyb24=?= | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by kamranasdasdas | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.