Rounding floats with f-string [duplicate]

Using %-formatting, I can specify the number of decimal cases in a string:

x = 3.14159265
print('pi = %0.2f' %x)

This would give me:

pi = 3.14

Is there any way of doing this using f-strings in Python 3.6?


How about this

x = 3.14159265
print(f'pi = {x:.2f}')

Docs for f-strings