![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have some code that takes Double.MaxValue and converts it to a string, but when I try to convert it back to a double, it fails. Shouldn't the value be able to be converted back to a double without error? Here is a simple code sample that demonstrates the problem: try { Double dbl = double.MinValue; //String sdbl = dbl.ToString(); // This errors as well String str = dbl.ToString("N"); // This throws "Value was either too large or too small for a Double." Double dbl2 = Convert.ToDouble(str); } catch (Exception ex) { System.Diagnostics.Debug.Write(ex.Message); } |
#3
| |||
| |||
|
|
I have some code that takes Double.MaxValue and converts it to a string, but when I try to convert it back to a double, it fails. Shouldn't the value be able to be converted back to a double without error? Here is a simple code sample that demonstrates the problem: try { Double dbl = double.MinValue; //String sdbl = dbl.ToString(); // This errors as well String str = dbl.ToString("N"); // This throws "Value was either too large or too small for a Double." Double dbl2 = Convert.ToDouble(str); } catch (Exception ex) { System.Diagnostics.Debug.Write(ex.Message); } Perhaps you should try the round-trip format string instead |
#4
| |||
| |||
|
|
Kevin Blakeley wrote: I have some code that takes Double.MaxValue and converts it to a string, but when I try to convert it back to a double, it fails. Shouldn't the value be able to be converted back to a double without error? Here is a simple code sample that demonstrates the problem: try { Double dbl = double.MinValue; //String sdbl = dbl.ToString(); // This errors as well String str = dbl.ToString("N"); // This throws "Value was either too large or too small for a Double." Double dbl2 = Convert.ToDouble(str); } catch (Exception ex) { System.Diagnostics.Debug.Write(ex.Message); } Perhaps you should try the round-trip format string instead String str = dbl.ToString("R"); Peter |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |