s-yadav / react-number-format

React component to format numbers in an input or as a text.
MIT License
3.87k stars 409 forks source link

onValueChange function changes entered digit to 0 after 16th digits #846

Closed SmokeGuap closed 1 month ago

SmokeGuap commented 4 months ago

Describe the issue and the actual behavior

 onValueChange={({floatValue}: NumberFormatValues) => {
          if (floatValue) {
            onChange(floatValue);
          }
        }}

After entering 16th digits, the next digit is converted to zero.

Example: Enter 16 digits: 5 555 555 555 555 555 Enter next one 5: 55 555 555 555 555 550

Describe the expected behavior

Example: Enter 16 digits: 5 555 555 555 555 555 Enter next one 5: 55 555 555 555 555 555

Provide a CodeSandbox link illustrating the issue

codesandbox

Provide steps to reproduce this issue

Please check the browsers where the issue is seen

Spielboerg commented 4 months ago

I think this has to do with the MAX_SAFE_INTEGER (9007 1992 5474 0991 < 17th digit number).

Just try console.log(Number(55555555555555555)) and you will get the same result.

s-yadav commented 4 months ago

For long integers, using string representation of those numbers is better. You can use value from NumberFormatValues