Jump to content
The simFlight Network Forums

A few issues with Windows Culture settings


Recommended Posts



I am using the method below to get a distance from where the aircraft is to a given point:

private double findDistance(string newLon, string newLat)                               
            FsLatLonPoint ICAO;
            FsLongitude lon1 = new FsLongitude(Convert.ToDouble(newLon));
            FsLatitude lat1 = new FsLatitude(Convert.ToDouble(newLat));

            ICAO = new FsLatLonPoint(lat1, lon1);                                             
            lon1 = new FsLongitude(playerLongitude.Value);                                    
            lat1 = new FsLatitude(playerLatitude.Value);
            FsLatLonPoint currentPosition = new FsLatLonPoint(lat1, lon1);                   
            double distance = 0;
            distance = currentPosition.DistanceFromInNauticalMiles(ICAO);
            return distance;

The method works perfectly on a system with '.' (dot) as a decimal separator, but anyone using the program on, say, a Portuguese computer where the decimal separator is a ',' (comma) will yield incorrect results.


In english, the value of lon1 before processed will be {E000° 00.00'} and on a Portuguese computer it will be {E000° 00,00'} and the routines in the DLL don't seem to cope with that.


What is the best way to solve this culture issue? I tried converting to string where i can change the comma for a dot easily, but then i cannot feed the FsLatLonPoint with the string and couldn't really find a way to convert the datatypes...


Thank you very much,


Edited by NaMcO
Link to comment
Share on other sites

Hi Nuno,


I've tried your exact code running under the culture code 'en-GB' and 'pt-PT'. Both give me back the same results (which seem sensible) and no exceptions are thrown.


Obviously the input string for the Convert.ToDouble needs to have the . or , appropriate to the culture code.


So, running under en-GB I entered "53.024" for latitude, and "2.21" as longitude. I got back "283.196744307048" after running ToString() on the double returned from your function.


Then I switch to pt-PT and I entered "53,024" for latitude, and "2,21" as longitude. I got back "283,196744307048".


As far as I can see it's running okay.


Can you give me any more information about the problem, e.g. the exact strings you are supplying to newLon and newLat? 


Also when you say you are getting incorrect results what is the incorrect value and what are you expecting?





Link to comment
Share on other sites

Hello Paul and thank you for your quick reply.


I'm feeding the method with (example)...

double distance = findDistance(ap_deplng, ap_deplat);

...where the ap_deplng and ap_deplat variables are strings like '-9.13952' and '38.7813'.


When i am at the departure airport and i feed the method with the coordinates for the departure airport, it should return a value very close to '0' because that's where i am. This works fine in 'en-US', but when i change the locale to "pt-PT" for instance, the value returned is '3389... something'.


If i change the ',' to '.' in my windows settings, everything returns back to normal.


A few minutes ago after finally deciphering MSDN help, i tried doing this before InitializeComponent(); is called...

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);

And everything works fine in every computer. This set the thread culture to en-US, fortunately i only run one thread...



Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.