Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty String to Double C#

Tags:

c#

double

At this moment i am trying to get a double value from textbox like this:

String.IsNullOrEmpty(textBox1.Text) ? 0.0 : Double.Parse(textBox1.Text)

But there is a problem, i cant get how to parse empty textbox?

For example if to try this code with OleDb and Excel with empty textbox, we will get error

System.FormatException: Input string was not in a correct format.

like image 842
MyMomSaysIamSpecial Avatar asked Sep 25 '12 12:09

MyMomSaysIamSpecial


1 Answers

double val;
if(!double.TryParse(textBox.Text,out val))
    val = 0.0
like image 86
yukaizhao Avatar answered Oct 18 '22 20:10

yukaizhao