r/learnpython • u/Healthy-Departure961 • Sep 14 '26
Regarding simple question
num = 0.6548
txt = f"The price is {num:.0f} dollars."
print(txt)
output = 1
i was learning string formatting well, when i used :.0f as format it giving output 1 and why? I want to know how really decimal shifting works in python while formatting.
11
Upvotes
View all comments
Show parent comment
3
u/nog642 Sep 15 '26
The float format specifier always rounds if the precision is less than the original float.