two digits after decimal point in java code example
Example 1: java printf double 2 decimal places
printf("%. 2f", value);
Example 2: how to set 2 decimal places in java
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
System.out.println(df.format(decimalNumber));
Example 3: float format decimal places
num = 1.234
print("{:.2f}".format(num))
>> 1.23
print(f"{num:.2f}")
>> 1.23