Java double 2 décimal
String result = String.format("%.2f", value);
Epic Coder
String result = String.format("%.2f", value);
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
System.out.println(df.format(decimalNumber));
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 res = Math.round(a * 100) / 100;