-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed as not planned
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
Description
There is a discrepancy between the default float formatting achieved in different ways, see the source code snippet. It would be appropriate if using :f would by default give the same effect to a float as printing that number without using :f. Currently this is not the case, using :f unexpectedly changes the number of digits printed after the decimal point. Unexpectedly, because it changes one default setting to a completely different default setting.
value = 1.123456789
print(value) # print result is 1.123456789
print(f"{value}") # print result is 1.123456789
print(f"{float(value)}") # print result is 1.123456789
print(f"{value:f}") # print result is 1.123457
print(f"{float(value):f}") # print result is 1.123457
# However,
#
# "[...] With no precision given, uses a precision of 6 digits
# after the decimal point for float [...]"
#
# https://docs.python.org/pl/3/library/string.html#formatstrings
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)