cchanxzy / react-currency-input-field

React component for an input field
MIT License
648 stars 118 forks source link

Bluring component causes certain currencies to lose most of input #310

Closed willyls-VG closed 10 months ago

willyls-VG commented 1 year ago

Describe the bug When entering amounts in JPY or KRW, we lose all but the first two digits on blur. Then padRight(3, '0')

e.g.:

enter: 123456 => result: 120 enter: 1 => result: 100

To Reproduce Steps to reproduce the behavior:

  1. Create component with this setup: value={value1} decimalScale={2} onValueChange={handleOnValue1Change} intlConfig={{ locale: "ja-JP", currency: "JPY" }} disableAbbreviations
  2. Enter amount in first input
  3. Enter 12345
  4. Blur from

Expected behavior See 12,345 in field

Code Sandbox If applicable, please fork this CodeSandbox template and customise it to replicate your issue.

Additional context

sspoth commented 1 year ago

I am getting the same error. The issues seems to be because these currencies are 0 decimal currencies Zero-decimal currencies and the behavior for decimalScale is wrong. Zero-decimal currencies should not have any decimal scale since they don't have fractions so the intlConfig of these should be zero. Now where the bug exists is that for some reason it assumes every value after the first is a decimal so if ur decimalScale is 2 then 123456 => result: 120. however, even if you change your decimal scale to 0, the result will be 123456 => result: 1 because the code is incorrectly interpreting that 23456 are decimal values

mc-alt commented 1 year ago

I am also experiencing this issue with decimalScale: 2 (we have had to disable it for now)