This post is about C# and .Net, but some info is valuable for other techonolgies.
Since I can remember, I've been having problems with apps or games that crash because of a different style of parsing decimal numbers. It happens very often, from CAD apps, libraries to web pages. I'm not sure whether it is ignorance or lack of knowledge, but it's really annoying.
What's the problem? Here is a wiki article about it, but it short:
Here is a map that shows what kind of decimal separator (decimal mark) is used around the world.
Decimal marks:
Most of the Europe, South America write 1 000 000,00 or 1000000,00 sometimes 1.000.000,00 as opposite to "imperial" (marked as blue) write 1,000,000.00
Let me just give you a few from all problems that I encoutered last month.
Mirosoft XNA for Windows Phone 7 example: There is a very neat class that parse XML file to produce XNA animation
/// <summary>
/// Loads animation setting from xml file.
/// </summary>
private void LoadAnimiationFromXML()
{
XDocument doc =
XDocument.Load("Content/Textures/AnimationsDefinition.xml");
XName name = XName.Get("Definition");
var definitions = doc.Document.Descendants(name);
if (animationDefinition.Attribute("Speed") != null)
{
animation.SetFrameInvterval(TimeSpan.FromMilliseconds(
double.Parse(animationDefinition.Attribute("Speed").Value)));
}
double.Parse
throws an exception, one simple soultion is to use XmlConvert.ToDouble();
or parse with InvariantCulture
.
.Net app that use CSV files to store input vector as CSV - also throws.
Another .Net app that has some parsing inside the class - throws.
So how can we fix this?
Is there any other way to slove this? Can I make the app be invariant? Like starting the app in a different environment.
PS. I would like to run the app, but I don't have the code.
Properly set Thread.CurrentThread.CurrentCulture
and you wont have such problems.
Read here how to write culture independent code.
EDIT: If you do not have access to the code, you can run the application under a user account which has the expected culture set. For quick access you could create an english user, a german user, a french user..