0

I am trying to format float numbers in a fixed point notation: x.xxx, three digits following the decimal point regardless of the value of the number. I am getting surprising results. The first in particular would suggest that it is giving me three significant places rather than three digits after the decimal point. How do I tell it what I really want?

>>> print(f"{.0987:5.03}")  
0.0987
*expected: 0.099*
>>> print(f"{0.0:05.03}") 
000.0
*expected: 0.000*
>>> print(f"{0.0:5.3}")   
  0.0
Joymaker
  • 813
  • 1
  • 9
  • 23

1 Answers1

1
# added "3f" to specify decimals places

print(f"{.0987:5.3f}")
#expected: 0.099*
print(f"{0.9687:05.3f}")
#expected: 0.000*
print(f"{0.0:5.3f}")
HawkEyeSec
  • 26
  • 2