title: Which number <-> string conversions are always consistent, regardeless the localization settings?
body: <p>I have some issues with number &lt;-> string conversion i cannot sort out.</p>
  
  <p>We have written a serialization framework which uses several xml serialization techniques. But i have seen some inconsistent number conversions in the generated output:</p>
  
  <p>using:</p>
  
  <pre><code>var c = TypeDescriptor.GetConverter(double);
  var s = c.ConvertToString(value);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>var c = TypeDescriptor.GetConverter(double);
  return c.ConvertFromString(value.Value);
  </code></pre>
  
  <p>I get strings with comma separator like 3,33 and conversion back to double works, but will conversion back to double also work in another country which uses dot as separator? (I am in germany, we use comma, but besides that, i want the dot seperator)</p>
  
  <p>Then in another part of the code i convert the doubles in some structs directly by adding it to a XElement:</p>
  
  <pre><code>data.Add(new XElement("x", vector.x));
  </code></pre>
  
  <p>The XElement constructor converts the double to a string with dot like "3.33".</p>
  
  <p>It gets really strange, when i want to convert this string back to a double:</p>
  
  <pre><code>Double.TryParse(item.Value, out value.x);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>value.x = Convert.ToDouble(item.Value);
  </code></pre>
  
  <p>both ignore the dot and i have a double value of 333!?</p>
  
  <p>so i tried it there also with the TypeConverter code, but it gives me an exception, that "3.33" is no valid string for the double converter...</p>
  
  <p>Now what i really need is a number &lt;-> string conversion which always uses dot separator and also parses it righ, regardless the culture/localization settings...</p>
  
  <p>i am lost.. which should i use? i even tried things like:</p>
  
  <pre><code>    NumberFormatInfo provider = new NumberFormatInfo();
  
      provider.NumberDecimalSeparator = ".";
      provider.NumberGroupSeparator = " ";
      provider.NumberGroupSizes = new int[] { 3 };
  
      foreach (var item in CultureInfo.GetCultures(CultureTypes.AllCultures))
      {
          item.NumberFormat = provider;
      }
  </code></pre>
  
  <p>but it didn't help..
  thanks for any hint..</p>