title: How to determine thousands separator in JavaScript
body: <p>In order for <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString">toLocaleString</a> to work, the browser/JavaScript must know the user's locale and whether or not <a href="https://en.wikipedia.org/wiki/Decimal_mark#Hindu.E2.80.93Arabic_numeral_system">the specific locale uses "," or "."</a> for a thousands separator. Is it possible to access this data so that we can determine what the thousands separator is?</p>
  
  <p>If not, we can use a function like this...</p>
  
  <pre><code>var thousandsSeparator = (function(){
      if (typeof Number.prototype.toLocaleString === 'function') {
          var num = 1000;
          var numStr = num.toLocaleString();
          if (numStr.length == 5) {
              return numStr.substr(1, 1);
          }
      }
      return ","; // fall-back
  })();
  </code></pre>
  
  <p>...but it feels like an unnecessary hack.</p>