How to get Text control value into a numeric data type?
-
Hi All, I have a problem. I want to assign the value of text control to a variable of double type. If i do in this way double price = Text1.Text gives compilation error. If I do in this way double price = (double) Text1.Text gives me run time error of invalidcast type. How can I procceed in this case. Regards
Every thing will come to you if you have faith.
-
Hi All, I have a problem. I want to assign the value of text control to a variable of double type. If i do in this way double price = Text1.Text gives compilation error. If I do in this way double price = (double) Text1.Text gives me run time error of invalidcast type. How can I procceed in this case. Regards
Every thing will come to you if you have faith.
Hello Amol Ravatale, Every value type (i.e. int, double, char, etc.) has a Parse() function. This functions are all static, meaning you don't need to instantiate an object of that type. In your case, do the following:
double price = double.Parse(Text1.Text);
Best regards, Shy. -- modified at 11:53 Sunday 30th July, 2006
-
Hi All, I have a problem. I want to assign the value of text control to a variable of double type. If i do in this way double price = Text1.Text gives compilation error. If I do in this way double price = (double) Text1.Text gives me run time error of invalidcast type. How can I procceed in this case. Regards
Every thing will come to you if you have faith.
-
Well, you can always catch the exception in
Parse
:) Also, Parse is .NET 1.1, while TryParse is only .NET 2.0:)
Every thing will come to you if you have faith.