★★Java質問・相談スレッド151★★
■ このスレッドは過去ログ倉庫に格納されています
0754デフォルトの名無しさん
2012/02/13(月) 21:20:51.10static Number parse(String str) {
try { return Integer.valueOf(str); } catch (NumberFormatException e) {}
try { return Float.valueOf(str); } catch (NumberFormatException e) {}
throw new NumberFormatException();
}
System.out.println(parse("1").getClass()); //=> class java.lang.Integer
System.out.println(parse("1.0").getClass()); //=> class java.lang.Float
こうすればIntegerとFloatを区別してパースできる。
>>753
floatの精度知ってるの?
朝初心者は黙ってろ。
■ このスレッドは過去ログ倉庫に格納されています