Hi I have a big string like this :
"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
I wish to convert this string to long. But I failed. I did:
Long.parseLong(longString);
But I'm getting an error:
java.lang.NumberFormatException: For input string: "99999999.......
Are there any way to avoid this?
Use BigInteger class like this:
BigInteger number = new BigInteger(longString);
You need to use BigInteger. Long may not accommodate that big number.
Here is javadoc for BigInteger.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With