I have a simple code first I use this
Long.parseLong(4250120140405520712)
And it works but when I do this
Long.parseLong(42501201404055207123)
It fails. Adding an extra digit makes it throw a Number Format Exception. Can someone please explain
Assuming you're parsing Strings into longs:
The first one works because the number 4250120140405520712 (19 digits) is less than the maximum possible long value, Long.MAX_VALUE, 9223372036854775807L.
The second one fails because it's 20 digits long, bigger than 9223372036854775807L.
long variables can only hold a maximum of 9223372036854775807 see here for more information.
The reason the second one doesn't work is that you have exceeded the limit so the number format exception is shown.
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