I had experimented with some code on Python and I got strange results with :.2f.
>>> a = 4.34567
>>> a
4.34567
>>> f"{a:.2f}"
'4.35'
>>> "%.2f" % a
'4.35'
>>> "{:.2f}".format(a)
'4.35'
>
I expected results like:
>>> a = 4.34567
>>> a
4.34567
>>> f"{a:.2f}"
'4.34'
>>> "%.2f" % a
'4.34'
>>> "{:.2f}".format(a)
'4.34'
>
Also I getting strange results with other number (:.3f, ...) But I haven't seen strange results with :.5f
>>> f"{a:.3f}"
'4.346'
>>> f"{a:.f}"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Format specifier missing precision
>>> f"{a:.4f}"
'4.3457'
>>> f"{a:.5f}"
'4.34567'
I seen this in Python 3.11.2 on Linux. I didn't tried to reproduce it on old python version. Is that bug or feature?