Integer:
API:
public class Integer
static int parseInt(String s)
static String toString(int num)
- 方法
parseInt
把一个字符串转为整型数值 - 方法
toString
把整数转化为字符串
举例:
public static void main(String [] args)
{
String str = "25";
double b = Integer.parseInt(str);
System.out.println(b*10);
}
输出结果为
250
。
Double:
API:
public class Double
static double parseDouble(String s)
static String toString(double num)
- 方法
parseDouble
把一个字符串转为整型数值 - 方法
toString
把浮点数转化为字符串
举例:
public static void main(String [] args)
{
String str = "144.00";
double b = Double.parseDouble(str);
System.out.println(b*100);
}
输出结果为
14400
。
需要注意: 在把字符串转为数字时,不要遗漏前面的 Double. 和 Integer.