java format double to string with 2 decimals code example
Example 1: how to format a double in java to 2 decimal places
DecimalFormat df = new DecimalFormat("#.00");
Example 2: float format decimal places
num = 1.234
print("{:.2f}".format(num))
>> 1.23
print(f"{num:.2f}")
>> 1.23