[Python-Dev] Re: Be Honest about LC_NUMERIC [REPOST]

Christian Reis kiko at async.com.br
Tue Sep 2 13:42:30 EDT 2003


On Tue, Sep 02, 2003 at 11:29:55AM -0400, Tim Peters wrote:
> OTOH, *are* there locales that insert thousands_sep?  I don't know.  To get
> thousands_sep to appear via Python's locale.format(), in all locales I've
> tried so far it requires passing a true value for the optional "grouping"
> argument.  Like
> 
> >>> import locale
> >>> locale.setlocale(locale.LC_ALL, "german")
> 'German_Germany.1252'
> >>> x = 12345.0
> >>> locale.format("%g", x)  # no thousands_sep
> '12345'
> >>> locale.format("%g", x, 1)
> '12.345'
> >>>

At least with locale.format, if you want grouping, you pass in the third
argument (grouping=1) to format(). An example:

    >>> locale.setlocale(locale.LC_NUMERIC, 'da_DK')
    'da_DK'
    >>> locale.format("%.2f", 71630, 1)
    '71.630,00'

Now, from the glibc docs:

    [...] The SUSv2 specifies one further flag character.

       '      For decimal conversion (i, d, u, f, F, g, G) the output is
              to be  grouped with  thousands'  grouping characters if
              the locale information indicates any.  Note that many
              versions of gcc cannot parse this option  and  will issue
              a warning.  SUSv2 does not include %'F.

So unless I'm mistaken, this wouldn't really be an issue in our case if
explicit grouping isn't requested inside the python conversion functions.

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL



More information about the Python-Dev mailing list