So setzen Sie 2 Dezimalstellen in Java
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
System.out.println(df.format(decimalNumber));
Poised Polecat
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
System.out.println(df.format(decimalNumber));
DecimalFormat df = new DecimalFormat("0.00");
String myFormattedFloat = df.format(myFloat);
double test = 12.15;
DecimalFormat df = new DecimalFormat("#.0");
System.out.println(df.format(test)); // Console: 12.2
// # - prints a digit if provided, nothing otherwise
// . - indicates where to put the decimal seperator
// 0 - prints a digit if provided, 0 otherwise
double input = 3.14159265359;
System.out.format("double : %.2f", input); // 3.14
System.out.println("double : " + String.format("%.2f", input)); // 3.14
total = (double) 100 / listMember.size();
DecimalFormat df = new DecimalFormat("#.##");
String dx = df.format(total);
total = Double.valueOf(dx);
double res = Math.round(a * 100) / 100;