在我的计算程序中,我得到的结果是2.04145124554 e-5,所以我想要控制结果的小数精度。我使用了代码String.format("%.2f",myans),现在我得到的结果是0.00,但我期望的结果是2.04 e-5,现在我该怎么办?
发布于 2013-09-15 22:54:07
将其更改为
String.format ("%1.2f",myans)
发布于 2013-09-15 23:12:59
DecimalFormat类可以在这里为您提供帮助(有关http://docs.oracle.com/javase/6/docs/api/java/text/DecimalFormat.html的更多信息)。
下面的代码输出"2.04E-5“
DecimalFormat df = new DecimalFormat("#.##E0");
System.out.println(df.format(2.04145124554e-5));
// prints: 2.04E-5https://stackoverflow.com/questions/18813670
复制相似问题