2

The react-intl can format numbers based on locale. Now I am trying to add an input component in which users can enter number and it will be formatted to contain commas in appropriate places. For this in the handleChange, I want to parse this formatted number back to a Javascript number.

After going through the docs I could not find any way to do this. How can I parse formatted numbers? How do developers usually handle this flow of parsing and formatting dates and numbers?

  • 1
    I'm not that familiar with `react-intl` so I'm not sure if it handles your situation, but it's relatively easy in regular javascript: https://stackoverflow.com/questions/11665884/how-can-i-parse-a-string-with-a-comma-thousand-separator-to-a-number – Zevgon Feb 14 '18 at 06:40
  • There are locales in which there are period(.) or space instead of commas. I wanted to handle all the different cases that come based on a certain locale. – Syed Suhail Ahmed Feb 14 '18 at 06:45
  • Ohh I see, of course! My mistake – Zevgon Feb 14 '18 at 06:48
  • This is the best solution I can find, which is pretty funny: https://stackoverflow.com/questions/29255843/is-there-a-way-to-reverse-the-formatting-by-intl-numberformat-in-javascript – Zevgon Feb 14 '18 at 06:58

0 Answers0