文字列と数値の相互変換


INT型から文字列に     
int i;
String s = Integer.toString(i);
 
-----------------------------------------------------------
 
文字列からINT型に(sは文字列)
 
public int hantei(String s){
 int j=0;
 int ret=0;
 try{
  j=Integer.parseInt(s);
 } catch (NumberFormatException e){
  // 失敗
 }
 // 成功
}
 
-----------------------------------------------------------
 
Floatから文字列に
 
float i;
String s = Float.toString(i);
 
-----------------------------------------------------------
 
文字列からFloatに(sは文字列)
 
loat j; //Floatオブジェクト
float f;
int ret=0;
try{
 j=Float.valueOf(s);
} catch (NumberFormatException e){
 //エラー;
}
//成功;
f=j.floatValue();//Floatオブジェクトからfloatを取り出す
}