0

So I am looking at the following functionality https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString . In all the examples, its taking a US formatted number and going to another locale. Is there a way to go from another locale to US?

Example

9 000 to 9000

OR

99,99 to 99.99

Yes I can remove the space with regex, but there are other locale specific stuff I want to convert. Thanks

jrock2004
  • 3,229
  • 5
  • 40
  • 73
  • "In all the examples, its taking a US formatted number and going to another locale." You're mistaken. In all the example, it's taking *a JavaScript number* and formatting it per some locale. What you're really asking is how to parse a string given a particular locale, which has been asked before. – Jordan Running Nov 06 '17 at 20:43
  • 1
    Possible duplicate of [Culture sensitive ParseFloat Function in JavaScript?](https://stackoverflow.com/questions/4951738/culture-sensitive-parsefloat-function-in-javascript) – Jordan Running Nov 06 '17 at 20:44
  • `toLocaleString` is for formatting, but your question is about parsing. Consider improving the text of your question. The examples are not parsing en-US, they are all using literal numbers. – Ruan Mendes Nov 06 '17 at 21:02
  • @JordanRunning That question doesn't have very good answers. – Ruan Mendes Nov 06 '17 at 21:03
  • Possible duplicate of [How do I convert String to Number according to locale (opposite of .toLocaleString)?](https://stackoverflow.com/questions/25645163/how-do-i-convert-string-to-number-according-to-locale-opposite-of-tolocalestri) – Nickolay Nov 07 '17 at 01:33
  • Sounds like you have to either pick a library that does this ([globalize](https://github.com/globalizejs/globalize), [numeral.js](http://numeraljs.com/), [parse-decimal-number](https://www.npmjs.com/package/parse-decimal-number)) or roll your own as in the answers suggested by Jordan. – Nickolay Nov 07 '17 at 01:36

0 Answers0