posted 10 years ago

Dear friends,

This code is giving me NumberFormatException. I want to convert that String value to a Long/long data type.

Kindly help me out to solve this problem.

Regards,

Vijay

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

posted 10 years ago

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.

Compare:

9223372036854775807 vs

12121211193148935244

You'll need either a float or double, or java.math.BigInteger.

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions

It is sorta covered in the JavaRanch Style Guide. |