I am getting the value from Xamarin.ios with the following code.
However, when you change the language setting to Vietnamese, the value that should be entered as a number is received as data containing comma (,).
126.82645585 >>>>> 126,82645585
38.123456 >>>>> 38,123456
Does this happen in Swift or other languages?
public void SendLocation(object sender, LocationUpdatedEventArgs e)
{
CLLocation location = e.Location;
strUrl = "test.com/api/gps?token=1234";
strUrl = "&lati=";
strUrl = location.Coordinate.Latitude;
strUrl = "&longi=";
strUrl = location.Coordinate.Longitude;
strUrl = "&alti=";
strUrl = location.Altitude;
}
CodePudding user response:
What is happening here is that converting a double or a float to a string, C# automatically respects the current Culture set for the App.
This means that the decimal separator will vary from language to language, and it will change depending on which you've selected.
If you consistently want to have the same decimal separator. You can tell C# to format it invariant of culture.
strUrl = location.Coordinate.Longitude.ToString(CultureInfo.InvariantCulture);
This should save the decimal separator as .
, if you want a different formatting you can implement your own IFormatProvider
which dictates what should be done.