不同数据类型之间的转换

版权声明:转载请注明出处,个人创作不易 https://blog.csdn.net/qq_39123517/article/details/87924527

(1)将字符串String转化为整型int。

int i = Integer.parseInt(str);

int i = Integer.valueOf(my_str).intvalue();

:字符串转换成Double、Float、Long的方法大同小异。

(2)将字符串String转换成为Integer。

Integer integer = Integer.valueOf(i);

(3)将整数int转换成字符串String有3种方法。

String s = String.valueOf(i);

String s = Integer.toString(i);

String s = ""+i;

:字符串转换成Double、Float、Long的方法大同小异。

(4)整型int转换为Integer。

Integer integer = new Integer();

(5)将Integer转为字符串String。

Integer integer = String();

(6)将Integer转化为int。

int num = Integer.inValue();

(7)将String转换为BigDecimal。

BigDecimal d_id = new BigDecimal(str);

猜你喜欢

转载自blog.csdn.net/qq_39123517/article/details/87924527