Reputation: 29
I wanted to know is it possible format a double to round to two decimal places with trailing zeros without using DecimalFormat
, or importing anything for that matter? I've been trying to think of one for the past half hour and I can't figure it out.
Upvotes: 0
Views: 253
Reputation: 7994
You can use String.format();
String s = String.format("my double: %.2f", 3.54123);
System.out.println(s);
or directly printf
System.out.printf("my double: %.2f%n", 3.54123);
Upvotes: 1