强制一次写整个数字 [英] Force a double to write the whole Number
本文介绍了强制一次写整个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Java中强制执行 double
来打印整个数字。不像1.65462165887E12.But像1654621658874684?
谢谢
解决方案
适当格式化例如:
System.out.printf(%。1f,1654621658874684.0);
或者你可以像String一样使用它:
这意味着逗号后面的数字
String value = String.format(%1f,1654621658874684.0); $$ 1 $
请注意, double
不是无限精准。它具有关于 15到17位十进制数字的精度。如果您需要任意精度的浮点数,请使用 BigDecimal
而不是 double
。
How can I force a double
in Java to print the whole number. Not like 1.65462165887E12.But like 1654621658874684?
Thanks
解决方案
Format it appropriately. For example:
System.out.printf("%.1f", 1654621658874684.0);
Or you can use it like a String:
//"%.1f" this mean, how many number after the comma
String value = String.format("%.1f", 1654621658874684.0);
Be aware that double
is not infinitely precise. It has a precision of about 15 to 17 decimal digits. If you need floating-point numbers with arbitrary precision, use BigDecimal
instead of double
.
这篇关于强制一次写整个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文