Closed yasincaliskan closed 3 years ago
This may help: https://github.com/globalizejs/globalize/blob/master/doc/api/number/number-parser.md but I think we will need to strict the locales.
This answer seems promising. It references this: https://observablehq.com/@mbostock/localized-number-parsing
Thank you for your suggestions!
shouldFormatToLocaleString
prop. Because we can use NumberInput
for different purposes like phone number or ID. And we can add a locale
prop but if the user doesn't pass this prop, we can use the system locale as default. I don't think it will cause any problem.Intl.NumberFormat
is working fine but format
method assumes that taking like 123456.05
number. formatToParts
method is very useful but I couldn't combine this method with our RegExp yet. I guess there is some weird stuff 🤔 DECIMAL_NUMBER_SEPARATOR
and THOUSANDTHS_SEPARATOR
we can handle with numberToString
function. Because I think so only Intl.NumberFormat
not enough.Looks like working well with your help. Thank you @edizcelik 🎉
But there is one more thing. We should think of the following replace
scope for other locales. It's working fine with only0123456789
.
let parsedNumber = value
.replace(new RegExp(NOT_NUMBER_OR_DECIMAL_POINT_REGEX), "")
...
It couldn't work for any different number of characters. (see last story example) Have you an idea for this?
Decription
numberToString
utility has added. Locale parameter is"en"
as default.shouldFormatToLocaleString
is true,numberToString
function trigger and return the converted value.