java - Integer.parseInt("9999999990"); -
this question has answer here:
i getting numberformatexception string 9999999990 not when use 1111111110 when call integer.parseint on string. let me know wrong.
string str="9999999990"; int f = integer.parseint("2147483647");// no exception here int x =integer.parseint(str); // exception thrown here
integer.parseint
throw exception when it's parsing can't represented int
. first example 10 billion, larger largest possible int
, little on 2 billion.
integer.parseint(string)
delegates integer.parseint(string, 10)
, version takes radix, , javadocs state:
an exception of type numberformatexception thrown if of following situations occurs:
- the first argument null or string of length zero.
- the radix either smaller character.min_radix or larger character.max_radix.
- any character of string not digit of specified radix, except first character may minus sign '-' ('\u002d') or plus sign '+' ('\u002b') provided string longer length 1.
- the value represented string not value of type int.
(emphasis mine)
if need parsed, can use long.parselong
, handle larger numbers.
Comments
Post a Comment