Format zu 2 oder n Dezimalstellen Python
num = 123.4567
formatted_num = '{0:.2f}'.format(num) # to 2 decimal places
# formatted_num = '123.46'
Anxious Alligator
num = 123.4567
formatted_num = '{0:.2f}'.format(num) # to 2 decimal places
# formatted_num = '123.46'
print(format(432.456, ".2f"))
>> 432.45
print(format(321,".2f"))
>> 321.00
float = 2.154327
format_float = "{:.2f}".format(float)
print(format_float)
a = 1.2138568
print(f'{a:.2f}')
a_float = 3.14159
formatted_float = "{:.2f}".format(a_float)
print("{0:.2f}".format(sum(query_marks)/len(query_marks)))