输入字符串999999999的NumberFormatException [英] NumberFormatexception for input string 999999999
问题描述
这是我的html
代码
<div class="form-group col-md-6">
<input type="text" class="form-control" name="phonenumber" placeholder="Enter Phone Number">
</div>
这是我的controller
int phonenumber=Integer.parseInt(request.getParameter("phonenumber").trim());
我得到NumberFormatException for input string '9999999999'
解决方法.
即使是一个数字,我为什么也不能解析它?
Even though it is a number why cannot I parse it?
推荐答案
9999999999
不在int
数据类型(-2 31 到2 由 Integer.MIN_VALUE
和 Integer.MAX_VALUE
常量.
9999999999
is outside the valid range of values for the int
data type (-231 to 231-1, inclusive), as specified by the Integer.MIN_VALUE
and Integer.MAX_VALUE
constants.
您不能在int
中表示完整的电话号码,因此您必须省略前缀和区号(0000000-9999999).否则,请改用long
(-2 63 到2 63 -1(含)),Long.parseLong()
将很乐意处理9999999999
.
You cannot represent a full phone number in an int
, you would have to omit the prefix and area code (0000000 - 9999999). Otherwise, use a long
instead (-263 to 263-1, inclusive), Long.parseLong()
will happily handle 9999999999
.
这篇关于输入字符串999999999的NumberFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!