Best way to Format a Double value to 2 Decimal places Discussion Dashboard › Category: Java › Best way to Format a Double value to 2 Decimal places 0 Vote Up Vote Down DHARMEDRA SAHU Staff asked 7 years ago Related DHARMEDRA SAHU Staff replied 7 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
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