Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这样的部分代码:
double double1 = 0.000112344; String string1 = "0.000112344"; System.out.println(String.valueOf(double1) + " : "+string1);
结果:
1.12344E-4 : 0.000112344
问题是,我如何将 double1 解析为显示 0.000112344 的字符串?
double double1 = 0.000112344; String string1 = "0.000112344"; System.out.printf("%.9f: %s%n", double1, string1);
0.000112344:0.000112344
一般来说,String.format("%.nf", double1)会产生一个double1四舍五入到n小数位的字符串表示。
String.format("%.nf", double1)
double1
n