4

文字列値をintに変換するには? 私は得てnumber format exceptionいます。

String s = "20.00";
int i = (Integer.parseInt(s));
System.out.println(i);

結果は次のようになりi=20ます。

4

2 に答える 2

2

String s = "20.00";

is not valid Integer value that is the reason its throwing NumberFormatException.

Format your number using either Double or Float then using narrow casting cast you number to int but you may loose precision if exists.

i.e. int I = (int) Double.parseDouble(str);

于 2013-10-25T12:47:33.777 に答える