Best way to Format a Double value to 2 Decimal places

Discussion DashboardCategory: JavaBest way to Format a Double value to 2 Decimal places
DHARMEDRA SAHU Staff asked 6 years ago
DHARMEDRA SAHU Staff replied 6 years ago

double[] arr = { 23.59004,
35.7,
3.0,
9
};

for ( double dub : arr ) {
System.out.println( String.format( “%.2f”, dub ) );
}

output:

23.59
35.70
3.00
9.00