react-currency-input
react-currency-input copied to clipboard
Negative value do not work for some locale
Hi,
I have a problem where the state is not calculated correct for negative values
I have found that it is the following code in index.js that is the problem
initialValue = Number(initialValue).toLocaleString(undefined, {
style : 'decimal',
minimumFractionDigits: props.precision,
maximumFractionDigits: props.precision
})
The minus sign is change to "−" (2212 MINUS SIGN) instead of "-" (002D HYPHEN-MINUS)
This result in that the logic for the following line fails
let negativeSignCount = (value.match(/-/g) || []).length;
Because it is looking for "-" (002D HYPHEN-MINUS), and in my case where the char is "−" (2212 MINUS SIGN) negativeSignCount equals 0, instead of 1
The solution should be to change:
initialValue = Number(initialValue).toLocaleString(undefined, {
style : 'decimal',
minimumFractionDigits: props.precision,
maximumFractionDigits: props.precision
})
to
initialValue = Number(initialValue).toFixed(props.precision);