[Python-ideas] Fixed point format for numbers with locale based separators

Łukasz Stelmach steelman at post.pl
Fri Jan 4 09:57:53 EST 2019


I would like to present two pull requests[1][2] implementing fixed point
presentation of numbers and ask for comments. The first is mine. I
learnt about the second after publishing mine.

The only format using decimal separator from locale data for
float/complex/decimal numbers at the moment is "n" which behaves like
"g". The drawback of these formats, I would like to overcome, is the inability
to print numbers ranging more than one order of magnitude with the same
number of decimal digits without "manually" (with some additional custom
code) adjusting precission. The other option is to "manually" replace
"." as printed by "f" with a local decimal separator. Neither of these option
is appealing to my.

Formatting 1.23456789 * n (LC_ALL=3Dpl_PL.UTF-8)
    | n |    ".2f" |    ".3n" |
    | 1 |     1.23 |     1,23 |
    | 2 |    12.35 |     12,3 |
    | 3 |   123.46 |      123 |
    | 4 |  1234.57 | 1,23e+03 |

In the application I want to create I am going to present users numbers
ranging up to 3 orders of magnitude and I (my users) want them to be
presented consistently with regards to number of decimal digits AND I
want to conform to rules of languages of my users. And I would like to
avoid the exponent notation by all means.

I can't say much about James Emerton's implementation or his intentions,
but please take a look at our patches and give your comments so either
of us or together we can implement this feature.

PS. In theory both implementations could be merged because James chose
to use "l" to use LC_MONETARY category and I chose "m" to use LC_NUMERIC.

[1] https://github.com/python/cpython/pull/11405
[2] https://github.com/python/cpython/pull/8612
Miłego dnia,
Łukasz Stelmach

More information about the Python-ideas mailing list