input string not in correct format exception

craftit

Member
Joined
Sep 19, 2006
Messages
23
Programming Experience
Beginner
hello everyone,
i tried converting a string from a textbox with initial value 0.0 to
double using convert.toDouble and i get this error message(input string not in correct format)
I put my code in a text changed event to be more specific.
can anyone assist me in debugging this exception.
Your assistance would be very much appreciated.
Thank you :confused:
 
It is probably because you belong to a culture that use comma as decimal separator. So if you tried to double string "0,0" that would be ok?
You can force convertion by a specific culture like this:
VB.NET:
[SIZE=2][COLOR=#0000ff]
Dim[/COLOR][/SIZE][SIZE=2] str [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"0.0"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] d [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Double[/COLOR][/SIZE][SIZE=2] = Convert.ToDouble(str, [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Globalization.CultureInfo([/SIZE][SIZE=2][COLOR=#800000]"en-US"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][SIZE=2]))
[/SIZE]
 
Back
Top