react-currency-input-field
react-currency-input-field copied to clipboard
Incorrect behaviour of formatValue
trafficstars
Describe the bug
formatValue formats some values incorrectly if an intlConfig is provided with a locale but not a currency.
To Reproduce
$ formatValue({
decimalSeparator: '.',
groupSeparator: ',',
disableGroupSeparators: false,
intlConfig: { locale: 'en-US' },
prefix: '',
value: '0.999972'
});
'1.999972'
Expected behavior
'0.999972'
Code Sandbox https://codesandbox.io/s/fervent-voice-72kz7d?file=/src/App.js
Additional context
The issue seems to be that in this case the NumberFormat isn't provided with the options about digits:
https://github.com/cchanxzy/react-currency-input-field/blob/d7c63d5f5398f30d37f3480129c8775a28d03f2e/src/components/utils/formatValue.ts#L97
But then the decimals are calculated from the pre-formatted value:
https://github.com/cchanxzy/react-currency-input-field/blob/d7c63d5f5398f30d37f3480129c8775a28d03f2e/src/components/utils/formatValue.ts#L114