[英]Java parse error when converting “9632580147” to int
In my java code, I have a string 9632580147
, and when I convert it into a int, using this code: 在我的Java代码中,我有一个字符串
9632580147
,当我使用以下代码将其转换为int时:
try{
sNumberInt = Integer.parseInt(sNumber);
} catch(NumberFormatException nfe) {
Log.d("NUMBER", nfe.getMessage());
return;
}
It goes into the catch block saying Invalid int: "9632580147"
... Does anyone know how to fix this? 它进入catch块,并说
Invalid int: "9632580147"
...有人知道如何解决此问题吗?
Thanks 谢谢
Max value of int
is 2147483647
and you are trying to pass 9632580147
which is greater. int
最大值为2147483647
并且您尝试传递的值大于9632580147
。 Try maybe Long.parseLong(sNumber)
试试也许
Long.parseLong(sNumber)
When you type 当您键入
int sNumber = 9632580147;
into your code, the compiler will tell you: 到您的代码中,编译器会告诉您:
The literal 9632580147 of type int is out of range int类型的文字9632580147超出范围
The reason is that your number is too big to fit into an int, use a long instead. 原因是您的数字太大,无法放入int中,请改用long。
似乎您传递的值大于32位:9632580147 = 1000111110001001011000001000110011(34位)
Integer
最大值为2147483647。如果要分割该数字,则需要将其解析为Long
。
The maximum value of the integer in Java is 2147483647
while your input 9632580147
is greater. Java中的整数最大值为
2147483647
而您输入的9632580147
更大。 Instead, use a long data type: 而是使用长数据类型:
long sNumberLong = Long.parseLong(sNumber);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.