• Post Reply Bookmark Topic Watch Topic
  • New Topic

NumberFormatException  RSS feed

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!