强制双倍写入整数

Lep*_*epo 4 java double

如何强制doubleJava中打印整个数字.不像1.65462165887E12.But喜欢1654621658874684?

谢谢

Jes*_*per 10

适当格式化.例如:

System.out.printf("%.1f", 1654621658874684.0);
Run Code Online (Sandbox Code Playgroud)

或者您可以像字符串一样使用它:

//"%.1f" this mean, how many number after the comma
String value = String.format("%.1f", 1654621658874684.0);
Run Code Online (Sandbox Code Playgroud)

请注意,这double不是无限精确的.它的精度约为15到17位十进制数.如果需要具有任意精度的浮点数,请使用BigDecimal而不是double.