Android中 int,float,Double,String 互相轉換

1 如何將字串 String 轉換成整數 int? 

A. 有兩個方法:

1). int i = Integer.parseInt([String]); 或 
i = Integer.parseInt([String],[int radix]);

2). int i = Integer.valueOf(my_str).intValue(); 

注: 字串轉成 Double, Float, Long 的方法大同小異. 

2 如何將整數 int 轉換成字串 String ? 

A. 有叄種方法:

1.) String s = String.valueOf(i);

2.) String s = Integer.toString(i); 

3.) String s = "" + i; 

 

注: Double, Float, Long 轉成字串的方法大同小異.

Double.toString(d);

Float.toString(f);

Long.toString(n);

發佈了27 篇原創文章 · 獲贊 46 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章