当我运行此代码时,我收到错误“无法从String转换为Double”,有什么想法吗?
DecimalFormat df = new DecimalFormat("##.###");
String [] data = null;
data = str.split(" ");
Double bat_avg = Double.parseDouble(data[4])/Double.parseDouble(data[2]);
bat_avg = df.format(bat_avg);
System.out.println(bat_avg);
答案 0 :(得分:4)
DecimalFormat#format(double)返回String
,因此输出必须是此类型而不是Double
:
String output = df.format(bat_avg);