Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to fix an application that has a problem with decimal separator
    text
    copied!<p><em>This post is about C# and .Net, but some info is valuable for other techonolgies.</em></p> <p>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.</p> <p>What's the problem? <a href="http://en.wikipedia.org/wiki/Decimal_mark" rel="nofollow noreferrer">Here</a> is a wiki article about it, but it short:</p> <p>Here is a map that shows what kind of decimal separator (decimal mark) is used around the world. <img src="https://i.stack.imgur.com/ODeSS.png" alt="map of diffrent decimal separator"></p> <p>Decimal marks:</p> <ul> <li>Period — Blue </li> <li>Comma — Green</li> <li>Non-West-Arabic Numerals — Red</li> <li>Unknown — Grey</li> </ul> <p>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</p> <p>Let me just give you a few from all problems that I encoutered last month.</p> <ol> <li>Number on webpages hard to read: Let's take one of the most <a href="http://www.youtube.com/watch?v=qrO4YZeyl0I" rel="nofollow noreferrer">viewed YT videos</a>. It shows me 390159851. Number above one million are very hard to read, what's the order of magnitude? Is it 39 mln or 390?</li> <li><p>Mirosoft <a href="http://create.msdn.com/en-US/education/catalog/" rel="nofollow noreferrer">XNA for Windows Phone 7 example</a>: There is a very neat class that parse XML file to produce XNA animation </p> <pre><code>/// &lt;summary&gt; /// Loads animation setting from xml file. /// &lt;/summary&gt; 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))); } </code></pre> <p><code>double.Parse</code> throws an exception, one simple soultion is to use <code>XmlConvert.ToDouble();</code> or parse with <code>InvariantCulture</code>.</p></li> <li><p>.Net app that use CSV files to store input vector as CSV - also throws.</p></li> <li><p>Another .Net app that has some parsing inside the class - throws.</p></li> </ol> <p>So how can we fix this?</p> <ul> <li>Fix the bug in code - possible only with avaible source code and tedious.</li> <li>Change the data (CVS, XML etc.) - even with possible, not very happy with mutating the data.</li> <li>Change the OS default decimal separator - not gonna happen.</li> </ul> <p><strong>Is there any other way to slove this?</strong> Can I make the app be invariant? Like starting the app in a different environment.</p> <p>PS. I would like to run the app, but I don't have the code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload