我有这样的代码:错误解析双java的
public void refreshResources(){
try{
String res = driver.findElement(By.cssSelector("#resources_metal")).getText();
System.out.println("Metal read: " + res);
res = res.replaceAll("\\u002e", ""); //Removes dots
System.out.println("Metal without dots: " + res);
this.metRes = Double.parseDouble(res);
System.out.println("Converted Metal: " + metRes);
}catch(NoSuchElementException error){
System.out.println("Error please try again");
}
这是我的输出:
金属阅读:47.386.578
金属没有点:47386578
转换金属: 4.7386578E7
问题是,为什么我的转换结束时会出现“E7”金属? 在此先感谢。
假设你参考这个[文章](https://stackoverflow.com/questions/6171823/how-can-i-change-2-5e7-to-a-normally-formatted-number)。 –
双精度不具有无限精度。这是你在科学记数法中的价值。 –
这会给你很多关于“为什么”问题的背景:https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency –