| Author |
NumberFormatException
|
Vijay Chandran
Ranch Hand
Joined: Jan 07, 2007
Posts: 175
|
|
Dear friends, This code is giving me NumberFormatException. I want to convert that String value to a Long/long data type. long a = Long.parseLong(str) also gives me NumberFormatException. Kindly help me out to solve this problem. Regards, Vijay
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
The number looks suspiciously like its a larger value than a long can hold. Have a look at BigInteger. [ October 23, 2007: Message edited by: Paul Sturrock ]
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
A long can only store numbers up to 9223372036854775807. Your number is larger than that, so it won't fit in a long. That's the reason of the exception. Compare: 9223372036854775807 vs 12121211193148935244 You'll need either a float or double, or java.math.BigInteger.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Vijay Chandran
Ranch Hand
Joined: Jan 07, 2007
Posts: 175
|
|
Thank you very much for the reply. I am getting the value as a String. How can i check that such a big value can be an integer or BigInteger. Regards, Vijay
|
 |
Nitesh Kant
Bartender
Joined: Feb 25, 2007
Posts: 1638
|
|
Originally posted by vijaychandran rajagopalan: How can i check that such a big value can be an integer or BigInteger.
Why not always use a BigInteger when you suspect that the value *can* be big.
|
apigee, a better way to API!
|
 |
 |
|
|
subject: NumberFormatException
|
|
|