java format string two decimal places or none code example
Example 1: java string format .2f
String.format("%.2f", 3.45);
Example 2: how to format a double in java to 2 decimal places
DecimalFormat df = new DecimalFormat("#.00");
String.format("%.2f", 3.45);
DecimalFormat df = new DecimalFormat("#.00");