<p>One of the fun parts of multi-cultural programming is number formats.</p>

<ul>
<li>Americans use 10,000.50</li>
<li>Germans use 10.000,50</li>
<li>French use 10 000,50</li>
</ul>

<p>My first approach would be to take the string, parse it backwards until I encounter a separator and use this as my decimal separator. There is an obvious flaw with that: 10.000 would be interpreted as 10.</p>

<p>Another approach: if the string contains 2 different non-numeric characters, use the last one as the decimal separator and discard the others. If I only have one, check if it occurs more than once and discards it if it does. If it only appears once, check if it has 3 digits after it. If yes, discard it, otherwise, use it as decimal separator.</p>

<p>The obvious "best solution" would be to detect the User's culture or Browser, but that does not work if you have a Frenchman using an en-US Windows/Browser.</p>

<p>Does the .net Framework contain some mythical black magic floating point parser that is better than <code>Double.(Try)Parse()</code> in trying to auto-detect the number format?</p>

[{'answer_id': 210, 'author': 'huseyint', 'author_id': 39, 'author_profile': 'https://Stackoverflow.com/users/39', 'pm_score': 5, 'selected': False, 'text': '<p>I don\'t know the ASP.NET side of the problem but .NET has a pretty powerful class: <a href="https://learn.microsoft.com/dotnet/api/system.globalization.cultureinfo" rel="nofollow noreferrer">System.Globalization.CultureInfo</a>. You can use the following code to parse a string containing a double value:</p>\n\n<pre><code>double d = double.Parse("100.20", CultureInfo.CurrentCulture);\n//  -- OR --\ndouble d = double.Parse("100.20", CultureInfo.CurrentUICulture);\n</code></pre>\n\n<p>If ASP.NET somehow (i.e. using HTTP Request headers) passes current user\'s CultureInfo to either CultureInfo.CurrentCulture or CultureInfo.CurrentUICulture, these will work fine.</p>\n'}, {'answer_id': 212, 'author': 'Chris Marasti-Georg', 'author_id': 96, 'author_profile': 'https://Stackoverflow.com/users/96', 'pm_score': 4, 'selected': False, 'text': '<p>You can\'t please everyone.  If I enter ten as 10.000, and someone enters ten thousand as 10.000, you cannot handle that without some knowledge of the culture of the input.  Detect the culture somehow (browser, system setting - what is the use case?  ASP?  Internal app, or open to the world?), or provide an example of the expected formatting, and use the most lenient parser you can.  Probably something like:</p>\n\n<pre><code>double d = Double.Parse("5,000.00", NumberStyles.Any, CultureInfo.InvariantCulture);\n</code></pre>\n'}, {'answer_id': 258, 'author': 'Ryan Fox', 'author_id': 55, 'author_profile': 'https://Stackoverflow.com/users/55', 'pm_score': 6, 'selected': True, 'text': "<p>I think the best you can do in this case is to take their input and then show them what you think they meant. If they disagree, show them the format you're expecting and get them to enter it again.</p>\n"}, {'answer_id': 430, 'author': 'Michiel de Mare', 'author_id': 136, 'author_profile': 'https://Stackoverflow.com/users/136', 'pm_score': 3, 'selected': False, 'text': '<p>The difference between 12.345 in French and English is a factor of 1000. If you supply an expected range where max &lt; 1000*min, you can easily guess. </p>\n\n<p>Take for example the height of a person (including babies and children) in mm.</p>\n\n<p>By using a range of 200-3000, an input of 1.800 or 1,800 can unambiguously be interpreted as 1 meter and 80 centimeters, whereas an input of 912.300 or 912,300 can unambiguously be interpreted as 91 centimeters and 2.3 millimeters.</p>\n'}]
['https://Stackoverflow.com/questions/192', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/91/']