Question How to convert string to double?

raysefo

Well-known member
Joined
Jul 21, 2010
Messages
207
Programming Experience
Beginner
hi,

I want to convert string to double.

Dim str As String = "1.5432"
Dim num As Double = Convert.ToDouble(str)

num should be 1.5432 but i get 15432

How can i get as it is in the string?
thanks in advance.

Best Regards
 
But it still seems like the same when i did it like the way u do above?

Dim num As Double = Double.Parse(str)

num still seems like 15432
 
can you show us the code you are using to do the conversion in full? Because both Convert.ToDouble and Double.Parse act the same and will consider decimal points.
 
I m writing it in c# sorry for that.

string currencyNameUSA = xn["CurrencyName"].InnerText;
string sel = xn["ForexSelling"].InnerText;
double sellingUSA = Double.Parse(sel);

sellingUSA is 15432.0
 
I m writing it in c# sorry for that.

string currencyNameUSA = xn["CurrencyName"].InnerText;
string sel = xn["ForexSelling"].InnerText;
double sellingUSA = Double.Parse(sel);

sellingUSA is 15432.0
Since it's coming from XML you may or may not know if it can even be converted to a Double or not, so I would recommend using the Double.TryParse() method for that.

Also this is a vb.net forum, convert your code to vb.net before posting it in the future
 
Right, because the default value for the decimal is .0 so if the number is "15432" and you convert it to a double the value stored is '15432.0'. When you display it to the user you can format it to not show the '.0' at that time.
 
Back
Top