Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IsDouble check for string in Vb.net?

I will get data in DataTable. I am going to iterate data in foreach. I will have all types of data in Datatable. Now I need to find Double for each item (string) in DataTable. How to find IsDouble for string?

Ex:

I have "21342.2121" string. I need to covert this to Double. But sometimes the data will be "TextString". So I can't use Double.Parse().

How to handle this?

like image 828
James123 Avatar asked Nov 23 '25 09:11

James123


2 Answers

Dim val as Double
Double.TryParse("MyString", val)
Double.TryParse("1234.567", val)

First TryParse() will return false. Second TryParse() will return true and place 1234.567 into val.

like image 108
Adam Lear Avatar answered Nov 24 '25 22:11

Adam Lear


Try Double.TryParse. This will return false if the number is not in a valid/recognized format, allowing you to do whatever you need to do in this scenario.

like image 36
Will Vousden Avatar answered Nov 24 '25 21:11

Will Vousden