JS 变量类型互相转换
转载自:http://zhaizhiyuan.blog.163.com/blog/static/1897672632009093147268/
Java中几种常用的数据类型之间转换方法: 1. short-->int 转换
exp: short shortvar=0;
int intvar=0;
shortvar= (short) intvar
2. int-->short 转换
exp: short shortvar=0;
int intvar=0;
intvar=shortvar;
3. int->String 转换
exp: int intvar=1;
String stringvar;
Stringvar=string.valueOf (intvar);
4. float->String 转换
exp: float floatvar=9.99f;
String stringvar;
Stringvar=String.valueOf (floatvar);
5. double->String 转换
exp double doublevar=99999999.99;
String stringvar;
Stringvar=String.valueOf (doublevar);
6. char->String 转换
exp char charvar=’a’;
String stringvar;
Stringvar=String.valueOf (charvar);
7 String->int、float、long、double 转换
Exp String intstring=”10”;
String floatstring=”10.1f”;
String longstring=”99999999”;
String doubleString=”99999999.9”;
Int I=Integer.parseInt (intstring);
Float f= Integer.parseInt (floatstring);
Long lo=long. parseInt (longstring);
Double d=double. parseInt (doublestring);
8 String->byte、short 转换
Exp String s=”0”;
Byte b=Integer.intValue(s);
Short sh=Integer.intValue(s);
9 String->char 转换
Exp String s=”abc”;
Char a=s.charAt(0);
返回字符a
10 String-->boolean 转换
String s=”true”;
Boolean flag=Boolean.valueOf (“s”);