当前位置: 技术问答>java相关
java中int, double 转化成String, String转化成double,怎么做?请给个例子.
来源: 互联网 发布时间:2015-01-15
本文导语: | int i = 10; double j=1.0; String str_i=Integer.toString(i); String str_j = Double.toString(j); double dd = Double.valueOf("123.2"); | int 转化成String: int i=10; String str=Integer.toString(i); double 转化成String: ...
|
int i = 10;
double j=1.0;
String str_i=Integer.toString(i);
String str_j = Double.toString(j);
double dd = Double.valueOf("123.2");
double j=1.0;
String str_i=Integer.toString(i);
String str_j = Double.toString(j);
double dd = Double.valueOf("123.2");
|
int 转化成String:
int i=10;
String str=Integer.toString(i);
double 转化成String:
double d=10.0;
String str=Double.toString(d);
String 转化成double:
String str="123456";
double d=Double.valueOf(str).doubleValue();
int i=10;
String str=Integer.toString(i);
double 转化成String:
double d=10.0;
String str=Double.toString(d);
String 转化成double:
String str="123456";
double d=Double.valueOf(str).doubleValue();
|
public class trans{
public static void main(String ag[]){
int a = 12;
double b = 122;
String s1 = a + "";
String s2 = b + "";
System.out.println("s1 and s2: "+s1+" "+s2);
String s = "12345";
try{
double d = (new Double(s)).doubleValue();
System.out.println("d: "+d);
}
catch(NumberFormatException e){
System.out.println("s is not a number");
}
}
}
public static void main(String ag[]){
int a = 12;
double b = 122;
String s1 = a + "";
String s2 = b + "";
System.out.println("s1 and s2: "+s1+" "+s2);
String s = "12345";
try{
double d = (new Double(s)).doubleValue();
System.out.println("d: "+d);
}
catch(NumberFormatException e){
System.out.println("s is not a number");
}
}
}