1

I'm editing a web based program at the moment. It is used all over the globe. I'm adding a number based field. I want to be able to allow the end user to enter in the number the way they want in their local locale. I see that there is a function called Number.toLocaleString() that will give me what I need. However, I can't seem to find an inverse function.

Take the string "1,000" for example. If my user's locale is en-US, I want it to be interpreted as 1000. If my user's locale is de-DE then it should be interpreted as 1. What is the standard way of doing this in JavaScript?

Jason Thompson
  • 4,643
  • 5
  • 50
  • 74

1 Answers1

0

Javascript has pretty much no locale support beyond just detecting what is set. For that, see the navigator object, and this other question.

If you want locale specific parsing, you'll need to use one of the many libraries out there. Checkout localplanet. It has a formatter for integers and decimals.

Community
  • 1
  • 1
heneryville
  • 2,853
  • 1
  • 23
  • 30