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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With