I have a method like this:
Integer.parseInt(myInt)
not this integer becomes to long and I'm getting the following exception:
java.lang.NumberFormatException: For input string: "4000123012"
what can I do to avoid this error and still keep alle the functions runnning?
I tried to use BigInteger
but there is no parse
method, or I did not found it.
Firstly, take two BigInteger objects and set values. BigInteger one, two; one = new BigInteger("99"); two = new BigInteger("978"); Now, parse BigInteger object “two” into Binary.
The parseInt method parses a value as a string and returns the first integer. A radix parameter specifies the number system to use: 2 = binary, 8 = octal, 10 = decimal, 16 = hexadecimal. If radix is omitted, JavaScript assumes radix 10. If the value begins with "0x", JavaScript assumes radix 16.
Use it like this.
BigInteger number = new BigInteger(myInt);
My solution :
String sLong = "4000123012";
long yourLong = Long.parseLong(sLong);
System.out.println("Long : "+yourLong);
OutPut :
Long : 4000123012
You can use Long.parse for integers too:
Long.parseLong(myInt)
which of course returns a long
.
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