Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
tried using
 var AB = Convert.ToDouble(T) * Simulation.B;

//T is the get property of myTextbox

used Double.Parse
I always have this:input string was not in a correct format
Posted

1.For converting from text box text to double you should use double.TryParse() method like below:
C#
double number =0.0;
double.TryParse(T.Trim(), out number);
var AB= number * Simulation.B)

2.You could also test the result of the TryParse and if the conversion is not OK to use a default value like below:
C#
double number =0.0;
if(double.TryParse(T.Trim(), out number) == false)
   number = 1.0; //Default value!
//
var AB= number * Simulation.B)
 
Share this answer
 
v3
Comments
Oluwasetemi! 8-Dec-14 1:31am    
if true number will be holding the value of my textbox right?
Raul Iloc 8-Dec-14 1:37am    
Right, true means good value!
Oluwasetemi! 8-Dec-14 2:41am    
Thanks Man!!!You are the boss.
Raul Iloc 8-Dec-14 2:52am    
Welcome!
Use Double.TryParse[^].
This will indicate an input is double type before doing the conversion.
 
Share this answer
 
Comments
Oluwasetemi! 8-Dec-14 1:01am    
Its not working as well:when I try to step in to the codes textbox property show Text="";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900