JAVA基本类型的转换

1、String转成Int

例1:
String str = "123";
try {
    int a = Integer.parseInt(str);
} catch (NumberFormatException e) {
    e.printStackTrace();
}
例2:
String str = "123";
try {
    int b = Integer.valueOf(str).intValue()
} catch (NumberFormatException e) {
    e.printStackTrace();
}

2、Double转成Int

例1:
double   d   =   12.0;   
int   i   =   (new   Double(d)).intValue();
例2:
double   d   =   12.0;   
int   i   =   (int)d;   

3、Integer转成String

Integer it = new Integer(10);

String str = it.toString();

4、Integer转int

Integer转换成int的方法

Integer i = new Integer(10); 
int k = i.intValue();
即Integer.intValue();

5、int转Integer

int转换成Integer

int i = 10;

Integer it = new Integer(i);

6、String转BigDecimal

String转换成BigDecimal

BigDecimal bd = new BigDecimal(str);

 7、double类型转成String顺便格式化

double wcl=0.00;//完成率
String zzwcl=new java.text.DecimalFormat("0.00").format(wcl);//最终完成率  double装换成String顺便格式化

 

posted @ 2016-10-19 18:40  李清欣  阅读(297)  评论(0编辑  收藏  举报