1、java中String字符串转化为数字
(1)转换为整型:
String str ="123";
int i = Integer.parseInt(str);
long l = Long.parseLong(str);
(2)转换为浮点型:
String str = "123.456 "; //要确保字符串为一个数值,否则会出异常
double d = Double.parseDouble(str);
float f = Float.parseFloat(str);
2、java中数字转化为String字符串
(1)整型转换为String字符串:
int i =123;
String s = Integer.toString(i);
(2)浮点型转换为String字符串:
float f =123.456;
String str = Float.toString(f);
double d =123.456;
String str = Double.toString(d);
JAVA中常用数据类型转换函数
string --> byte
Byte static byte parseByte(String s)
byte --> string
Byte static String toString(byte b)
char --> string
Character static String to String (char c)
string --> Short
Short static Short parseShort(String s)
Short --> String
Short static String toString(Short s)
String --> Integer
Integer static int parseInt(String s)
Integer --> String
Integer static String tostring(int i)
String --> Long
Long static long parseLong(String s)
Long --> String
Long static String toString(Long i)
String --> Float
Float static float parseFloat(String s)
Float --> String
Float static String toString(float f)
String --> Double
Double static double parseDouble(String s)
Double --> String
Double static String toString(Double)
2403




被折叠的 条评论
为什么被折叠?



