(float)Convert.ToDouble c#.net c# 2003/2005

  • Thread starter Thread starter trondhuso
  • Start date Start date
T

trondhuso

Hi group,

I've found some code that I want to use in a project that I am working
on, but the code is for c# .net and not 2003 or 2005 that I have
available.
In this code the program yells on (float)Convert.ToDouble(xml.value)
(which in this case is "8.25").
I am wondering if someone could tell me how the command is changed in
2003 or 2005 as it stops here.

best

Trond
 
Hi group,

I've found some code that I want to use in a project that I am working
on, but the code is for c# .net and not 2003 or 2005 that I have
available.
In this code the program yells on (float)Convert.ToDouble(xml.value)
(which in this case is "8.25").
I am wondering if someone could tell me how the command is changed in
2003 or 2005 as it stops here.

best

Trond

I actually found the solution right after this posting. the reason is
that I am in a country where we use comma as a decimal separator, so I
had to change it.
the changes are:
System.Globalization.CultureInfo enUSCulture = new
System.Globalization.CultureInfo("en-US");
(float)Convert.ToDouble(xml.Value, enUSCulture);
 
trondhuso said:
I actually found the solution right after this posting. the reason is
that I am in a country where we use comma as a decimal separator, so I
had to change it.
the changes are:
System.Globalization.CultureInfo enUSCulture = new
System.Globalization.CultureInfo("en-US");
(float)Convert.ToDouble(xml.Value, enUSCulture);

You probably wanted the InvariantCulture if your data has a common,
international format.

Also, you might want to look into float.Parse or float.TryParse instead of
the Convert class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top