0

_day.Latitude = "64.128339"

_day.Longitude = "-20.995595"

public override void Prepare(ItineraryDay day)
{
    _day = day;

    var isParseLatitude = double.TryParse(_day.Latitude, out var latitude);
    var isParseLongitude = double.TryParse(_day.Longitude, out var longitude);

    _dayPositionInfo = new DayPositionInfo(
        latitude,
        longitude,
        _day.RouteName);
}

enter image description here

As you can see in the picture, Latitude and Longitude are valid double values, but Parse does not work and returns false? Why, I do not understand something?

Ry-
  • 209,133
  • 54
  • 439
  • 449
Nikita Goncharuk
  • 695
  • 1
  • 7
  • 21
  • `double.TryParse` is culture-dependent, which seems like a bad default to me but there you go. – Ry- Nov 01 '18 at 08:28

2 Answers2

3

I suspect your current culture doesn't use the . character as a decimal separator, that's why Double.TryParse returns false.

If you know that the decimal separator is always a ., you can do something like this:

bool isValidLatitude = Double.TryParse("64.128", NumberStyles.Any, CultureInfo.InvariantCulture, out double latitude);

PS: if you need to check what is the decimal separator of your current culture, use

Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator
Rui Jarimba
  • 10,350
  • 10
  • 55
  • 79
-1
Convert.ToDouble("64.128339");
double.Parse("64.128339");
Umair Rasheed
  • 368
  • 3
  • 9