tags:

views:

42

answers:

2

i am converting a string to double

i would like to know in advanced whether it would case an error to convert a string to a double. for example if i try to convert "hello" to a double, it would give me an error.

is there a way for me to know ahead of time whether converting something will cause an error?

+6  A: 

You want Double.TryParse:

Dim PossibleDouble as Double
If Double.TryParse("hello", PossibleDouble) Then
  ''//Success!
Else
  ''//Not a double
End If
Michael Haren
Note--the weird comment format is to fake-out the syntax highlighter
Michael Haren
A: 

Ahh, I see what you meant now. The correct answer is TryParse as noted by Michael.

String string_val = 1.0;
double val;

val = System.Convert.ToDouble(string_val);
Sev