Forums Register Login

NumberFormatException

+Pie Number of slices to send: Send


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
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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.
And then the flying monkeys attacked. My only defense was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1179 times.
Similar Threads
Total number of object string creates?
is "String[] str = (String[])ObjArray"" Right?
When object created on Heap and when on Stack
==, why is it so ?
Converting byte array to long
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:05:54.