0

In React if the string is small like "1234" all is OK. However if we have long string like "123456789123456789" I get error. I am using ParseInt() function to convert my string to Int and I get an exception. How to fix this?

dotnetavalanche
  • 804
  • 2
  • 12
  • 25

2 Answers2

4

That number won't fit into an int. Your best bet is to use bignumber.js: https://github.com/MikeMcl/bignumber.js/

Note that this will return an array of numbers, if you want numbers of arbitrary length, use big-integer.

EDIT: for others who are curious, an int is 32 bits. This means that you can only store numbers up to 11111111 11111111 11111111 11111111 in binary, which is (signed) 2147483647 or (unsigned) 4294967295

fugiefire
  • 318
  • 1
  • 8
0

Try to use default parseInt() of javascript

https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/parseInt