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?
Asked
Active
Viewed 387 times
0
-
what is the error you are getting – Sumanth Madishetty Aug 19 '19 at 11:28
-
can you please add log – aman kumar Aug 19 '19 at 11:28
-
there is no such thing as `ParseInt`, it's `parseInt` – Vaibhav Vishal Aug 19 '19 at 11:35
2 Answers
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

Eduardo Teixeira de Souza
- 90
- 1
- 7