Lepo Lepo - 1 year ago 82
Java Question

Force a double to write the whole Number

How can I force a

in Java to print the whole number. Not like 1.65462165887E12.But like 1654621658874684?


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download