title: Saving and restoring the decimal point requested by the user under Windows
body: <p>We have a program that displays output and takes input in the user-specified locale but also reads text from and saves text to configuration files and the Windows registry in a standard format that doesn’t depend on the user’s locale. Both sets of actions use C library functions to convert between numbers and strings.</p>
  
  <p>To switch between the two actions there is some code that is intended to change the locale for numbers (including the decimal point character) for the lifetime of an object of the class:</p>
  
  <pre><code>class StandardLocale
  {
      std::string locale;
  
  public:
      StandardLocale()
          : locale(setlocale(LC_NUMERIC,nullptr))
      {
          setlocale(LC_NUMERIC,"C");
      }
  
      ~StandardLocale()
      {   
          setlocale(LC_NUMERIC,locale.c_str());
      }
  };
  </code></pre>
  
  <p>However there is one case where it doesn’t work correctly. If the locale is French but the decimal point is then set to <code>"."</code> in the Control panel additional settings the locale string is returned as <code>"French_France.1252"</code>, ignoring the decimal point setting. When the object goes out of scope the locale is reset to <code>"French_France.1252"</code>, which changes the decimal point character from the user’s setting to a comma.</p>