Java Integer.parseInt failed to parse a string

后端 未结 5 965
忘了有多久
忘了有多久 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 00:38

    Your number is too large to fit in an int which is 32 bits and only has a range of -2,147,483,648 to 2,147,483,647.

    Try Long.parseLong instead. A long has 64 bits and has a range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

提交回复
热议问题