
Want to display a Python float with a limited number of decimals?
Use .nf as an f-string’s format specifier. n is the number of digits to show after the decimal:
x = 123.45678
print(f'{x:.2f}') # 123.46
print(f'{x:.3f}') # 123.457
Note: It rounds the final digit!
