Java.lang.NumberFormatException: for input line: "20110328094108069414"

I try to convert the String value to long and get: java.lang.NumberFormatException: For input string: "20110328094108069414"

My code is:

  String buyId  = "PSFT_20110328114728073793";
  long bookId  = Long.parseLong(buyId  .replaceAll("PSFT_",""));

Error:

10:12:10,522 ERROR [STDERR] java.lang.NumberFormatException: For input string: "20110328094108069414"
10:12:10,522 ERROR [STDERR]     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
10:12:10,522 ERROR [STDERR]     at java.lang.Long.parseLong(Long.java:415)
10:12:10,522 ERROR [STDERR]     at java.lang.Long.parseLong(Long.java:461)
10:12:10,522 ERROR [STDERR]     at unilog.com.user.ejb.userDAOORCL.checkCWSUserReg(userDAOORCL.java:363)
10:12:10,522 ERROR [STDERR]     at unilog.com.user.ejb.userEJBBean.checkCWSUserReg(userEJBBean.java:141)
10:12:10,522 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:12:10,523 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
10:12:10,523 ERROR [STDERR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
10:12:10,523 ERROR [STDERR]     at java.lang.reflect.Method.invoke(Method.java:585)
10:12:10,523 ERROR [STDERR]     at org.jboss.invocation.Invocation.performCall(Invocation.java:359)
10:12:10,523 ERROR [STDERR]     at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:237)
10:12:10,523 ERROR [STDERR]     at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:158)
+5
source share
6 answers

I think you need to use BigInteger or BigDecimal

For instance:

BigInteger bi;

String buyId  = "PSFT_20110328114728073793";
bi  = new BigInteger(buyId.replaceAll("PSFT_",""));

Add a try-catch block, with a NumberFormatException

+5
source

The largest allowed longis

  9223372036854775807L

and your value:

  20110328094108069414L

long . BigInteger, , , , String . ( , , , , .)

+6

20110328094108069414 .

+1

, - , ? ? JodaTime? , : Joda time: String LocalDate?

0

I do not think that the label PSFT_20110328114728073793 was ever intended to be used arithmetically. This seems to be a combination of type, date, and id. As others pointed out, 20110328114728073793 will not fit for long. Perhaps splitting a string into its original parts makes sense for your use?

0
source

The number is out of range. Use BigInteger!

0
source

All Articles