// 將 字串 轉為 整數的方法
private int getIntValue (String param) {
// 宣告 區域變數
String tmp = getParameter(param);
int iValue = 0;
if ( tmp!= null) {
try { // 意外狀況處理
iValue = (int)Integer.parseInt(tmp);
// 或 Integer.parseInt(tmp).intValue();
} catch (NumberFormatException e) {
// 當 資料格式 不正確時
showStatus("Number format error for parameter " + param + ">" );
}
}
return iValue;
}
但有更快的直接轉
我猜就像之前一樣可能還要做別的動作
所以才需要再多寫一個方法在下面吧
若不用的話 用下面這個就ok哩
int istr= Integer.parseInt(str)//str字串轉成數字istr
String sint=String.valueOf(int)//數字int轉字串sint
2006.11.29 14:15
全站熱搜