To format a
double
in Java, use String.format
.Here's how you do it:
double aDouble = 1234.56789;
// 1,234.57
System.out.println(String.format("%,.2f", aDouble));
// 1234.57
System.out.println(String.format("%.2f", aDouble));
// 1234.6
System.out.println(String.format("%.1f", aDouble));