Click here to Skip to main content
15,910,787 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have one text box in c# windows form.
I am taking input.
next I want to convert that to double. Here is problem is coming.
double.TryParse(txtdisc.Text, out b);

i debugged and saw what is there actutally coming. In that text box value is there but in that "b" no value is coming.I declared "b" as double b=0.00.
so in "b" only 0 is coming. What to do.

What I have tried:

I tried in other ways also like convert.ToDouble and double.Parse but no use. I am getting this here only. other form same one worked with other values. Why like this.
what to do now.
Posted
Updated 13-Apr-17 2:18am
Comments
[no name] 13-Apr-17 8:09am    
"In that text box value", you saw WHAT value is there? Is it a string that is really a double? Are you checking the return value of TryParse?
vijay_bale 13-Apr-17 8:13am    
I checked. Here TryParse return value is 0.But in textbox value is there 156.
[no name] 13-Apr-17 8:44am    
Then there is something you aren't telling us. TryParse does NOT return 0.
vijay_bale 13-Apr-17 8:47am    
@NotPloitically,
double.TryParse(txtdisc.Text, out b);
thats it. Nothing to hide form you people, who are trying to help me.
[no name] 13-Apr-17 8:59am    
"Here TryParse return value is 0", TryParse does NOT return 0. So there MUST be something you are not telling us.

1 solution

Can you try with below piece of code -

double b;
bool IsDoubleValue = double.TryParse(textBox1.Text, out b);

//do whatever you want with this value
var doubleTypeValue = IsDoubleValue ? Convert.ToDouble(textBox1.Text) : 0;
 
Share this answer
 
Comments
vijay_bale 13-Apr-17 8:31am    
@ vinod, I tried What you gave here.but value 0 is coming to b.that textbox value is 156.
[no name] 13-Apr-17 9:08am    
Return type for TryParse id Boolean only, there might be something wrong if you get 0. Share the code
vijay_bale 13-Apr-17 9:16am    
IsDoubleValue False Is coming.
bool IsDoubleValue = double.TryParse(txtitmtotal.Text, out b);
double d=b* 10;
var doubleTypeValue = IsDoubleValue ? Convert.ToDouble(txtitmtotal.Text) : 0;

MessageBox.Show(d.ToString());
[no name] 13-Apr-17 9:51am    
Well in problem description you mention "txtdisc.Text" and in this code you are referencing "txtitmtotal.Text". So the question is which textbox really you want to use here and causing issue?
vijay_bale 13-Apr-17 9:54am    
I changed the text box thinking that maybe problem with that text box. so other one is showing here.

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