Convert "-12.0000" (string) to -12.0000 (double). It's possible? [duplicate]

2

Is it possible to convert "-12.0000" (string) to -12.0000 (double)?

Follow the code below:

var valor = "-12.0000";
var result = Convert.ToDouble(valor, CultureInfo.InvariantCulture); //-12 <--- perde zeros

Or if you prefer .NET Fiddle: link

    
asked by anonymous 06.10.2017 / 18:06

1 answer

0

You will have to pass the culture to not lose the 0, it will look like this:

double longitude = double.Parse(text, CultureInfo.InvariantCulture);

It is advisable to always use double for latitude and longitude.

    
06.10.2017 / 18:18