I think f”{4321.23456:_._6f}” is better than f”{4321.23456:_.6f}” as it preserves backwards compatibility and makes it obvious the separators comes both after and before the decimal place.
I’d be curious to understand why this doesn’t already use _ in the fractional part. An oversight? Intentional? Left for future generations to solve?
It is true that most human languages do not apply a thousands separator
to the fractional part, but they do often apply a narrow space instead.
I can’t show narrow spaces in this email, so I’ll use a regular space.
Pretend it is half the width of a digit, or even less:
12,345,678.000 123 456 789
Many European countries swap the decimal point and the comma; India, I
believe, groups the digits in fours rather than threes.
In any case, practicality beats purity: there is no typographical
convention to use underscores in any human language, as far as I know,
nevertheless it is a useful thing to do when programming. We support
underscores in numeric literals:
>>> 123_456.123_456
123456.123456
and we can output underscores in the integer part of the number. We
should support them in the fractional part as well.
Is there a way to say that the the dot must be followed by one or both of float_grouping and precision?
I believe this grammar specification would allow this f"{123:0.f}" which is invalid and meaningless.
Also, since we can format numbers in a non-round-trippable way, why not add an option to group the fractional part with a special space (something like float_grouping ::= "_" | "s"):
Since all this is language specific (What are fraction and group separators? What is the size of group?) should not it be in the locale module instead of general str method or builtin?
That boat sailed over the horizon a long time ago: we’ve accepted
underscores in numeric literals, and as output in the whole number part,
for a long time now.
We’re not suggesting a fully configurable formatting language capable of
specifying the group size and seperators, just allowing output of
underscores in the fraction part.