heyman333 / react-animated-numbers

👾 Library showing animation of number changes in react.js
MIT License
247 stars 30 forks source link

fix: includeComma not being cross-i18n-compatible #35

Closed juliusmarminge closed 2 years ago

juliusmarminge commented 2 years ago

Closes #34.

Since some i18n doesn't use comma as a thousand-separator, the locale should be explicitly stated to one which uses comma as a separator (e.g. en-US).

Before: CleanShot 2022-07-27 at 00 52 08

After: CleanShot 2022-07-27 at 00 52 49


In-Depth:

The reason the previous failed and displayed an additional 0 is because with my locale (which is Sweden), we use " " as the thousand separator, and when converting the localeString (in this case "10 159") to the array we would get [1, 0, 0, 1, 5, 9] since Number(" ") = 0.