Reputation: 387
Let's suppose we have the following code:
System.out.println(String.valueOf(100000000000.0));
Now the output to that is 1.0E11. But that is not what I want. (Looks bad on a highscore) I want it to output exactly 100000000000.0. Is there a way to do that?
Upvotes: 3
Views: 1130
Reputation: 4485
Refer to this ...
Quest
You can use DecimalFormat to format your value for displaying
Upvotes: 0
Reputation: 967
Format it appropriately. For example:
System.out.printf("%.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.
Or you could use String.format():
System.out.println(String.format("%.0f", 1654621658874684.0d));
Upvotes: 6