String转double
要将String类型转换为double类型,可以使用Double.parseDouble()方法。例如:
String str = "3.14";
double d = Double.parseDouble(str);
System.out.println(d); // 输出 3.14
需要注意的是,如果String类型的值无法转换为double类型,会抛出NumberFormatException异常。因此,在转换之前最好先做一些检查,例如使用正则表达式检查字符串是否只包含数字和小数点等。
原文地址: http://www.cveoy.top/t/topic/bGm5 著作权归作者所有。请勿转载和采集!