DecimalFormat, Maximum Fraction Digits
import java.text.DecimalFormat;
class FormatUtils {
private static final DecimalFormat formatter = new DecimalFormat();
static {
formatter.setDecimalSeparatorAlwaysShown(false);
formatter.setMaximumFractionDigits(2);
}
public static String format(double value) {
return formatter.format(value);
}
}
Related examples in the same category