I have a string value, containing longitude or latitude value.
However, when I try to convert this to a double, I end up with a number where the dot is removed and placed at the end.
This is not what I want. What am I missing?
This is the value I get: 200,5,1.4928184,0.1609203
and this is the method I use to get the value:
var responseBytes = ms.ToArray();
var encoding = new System.Text.ASCIIEncoding();
var coords = encoding.GetString(responseBytes);
var parts = coords.Split(new char[] { ',' });
//this piece of code returns me wrong values! When I debug this piece parts[2] is exactly 1.4928184
return new Coordinaat(Double.Parse(parts[2]),
Double.Parse(parts[3]));
See code example below for constructor:
public Coordinaat(double lat, double lon)
{
this.Latitude = lat;
this.Longitude = lon;
}
Output:
lat 114928184 lon 01609203
--> where did my dots go to??
You are probably under a culture (e.g German) which is causing this effect. Use CultureInfo.InvariantCultre
while parsing.
Double.Parse("123.22",CultureInfo.InvariantCulture)