Java Integer.parseInt failed to parse a string

后端 未结 5 969
忘了有多久
忘了有多久 2020-12-02 00:30

I\'m parsing a string of 15 digits like this:

String str = \"100004159312045\";
int i = Integer.parseInt(str);

I\'m getting an exception wh

5条回答
  •  天涯浪人
    2020-12-02 01:03

    because int's maximum value is a little above 2,000,000,000

    you can use long or BigInteger

    long has double the digits it can store (the max value is square that of int) and BigInteger can handle arbitrarily large numbers

提交回复
热议问题