Python 2 Dezimalstellen
print(format(432.456, ".2f"))
>> 432.45
print(format(321,".2f"))
>> 321.00
Wild Weasel
print(format(432.456, ".2f"))
>> 432.45
print(format(321,".2f"))
>> 321.00
>>> x = 13.949999999999999999
>>> x
13.95
>>> g = float("{:.2f}".format(x))
>>> g
13.95
>>> x == g
True
>>> h = round(x, 2)
>>> h
13.95
>>> x == h
True
formatted_float = "{:.2f}".format(a_float)
print("{:.6f}".format(variable_name))
x = 13.949999999999999999
g = float("{:.2f}".format(x))
>>>pi=3.141592653589793238
>>> float("{:.12}".format(pi))
3.14159265359
>>> float("{:.6}".format(pi))
3.14159