Search code examples
javanumberformatexception

Number Format Exception for String 13363190467160024386 while converting to Long


I am trying to convert a numeric String to Long, but it is giving me NumberFormatException.

I am getting NumberFormatException for this String 13363190467160024386

Long.parseLong(String s)

Below is the exception I am getting-

java.lang.NumberFormatException: For input string: "13363190467160024386"

Any suggestions why is it happening?


Solution

  • Absolutely - that number is greater than than Long.MAX_VALUE (9223372036854775807).

    Use BigInteger instead:

    BigInteger value = new BigInteger("13363190467160024386");