classification
Title: German number separators not working using format language and locale "de_DE"
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7, Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Peter.Stahl, eric.smith, mark.dickinson, skrah
Priority: normal Keywords:

Created on 2013-01-12 11:26 by Peter.Stahl, last changed 2013-01-14 16:49 by skrah. This issue is now closed.

Messages (6)
msg179785 - (view) Author: Peter Stahl (Peter.Stahl) Date: 2013-01-12 11:26
Yesterday, I opened a question on Stackoverflow that explains my problem in detail. Please read this page first:

http://stackoverflow.com/questions/14287051/german-number-separators-using-format-language-on-osx

A short summary: I'm on OSX 10.8.2. I wanted to format numbers according to the German numbering convention using Python's format language and the locale setting "de_DE". Actually, the following should work to achieve that:

>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'de_DE')
>>> '{0:n}'.format(1234.56)

The result of the last expressions should be 1.234,56. However, my result is 1234,56. More examples are on Stackoverflow.

According to what other SO members have found out, this is a problem with the locale settings of OSX because the grouping of numbers is not fully part of the locale "de_DE". On Windows, however, grouping works fine using the locale "deu_deu" which is not available on OSX.

Is this a bug? At least, it doesn't seem to be documented anywhere and is probably not the correct behavior even on OSX. Others have reported similar problems on OSX as well.

Do you have a quick solution for this issue? Thanks in advance.
msg179787 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2013-01-12 11:39
What is the output of this?

>>> locale.localeconv()                     
{'mon_decimal_point': ',', 'frac_digits': 2, 'p_sign_posn': 1, 'thousands_sep': '.', 'p_sep_by_space': 1, 'int_curr_symbol': 'EUR ', 'decimal_point': ',', 'mon_thousands_sep': '.', 'n_sep_by_space': 1, 'int_frac_digits': 2, 'currency_symbol': 'EUR', 'negative_sign': '-', 'mon_grouping': [3, 3, 0], 'positive_sign': '', 'n_cs_precedes': 0, 'grouping': [3, 3, 0], 'n_sign_posn': 1, 'p_cs_precedes': 0}


If 'grouping' is [], then this looks like a bug in OSX. Python gets
the values directly from the operating system.
msg179788 - (view) Author: Peter Stahl (Peter.Stahl) Date: 2013-01-12 11:52
Using the locale 'de_DE', the output is:

{'mon_decimal_point': ',', 'int_frac_digits': 2, 'p_sep_by_space': 0, 'frac_digits': 2, 'thousands_sep': '', 'n_sign_posn': 1, 'decimal_point': ',', 'int_curr_symbol': 'EUR ', 'n_cs_precedes': 1, 'p_sign_posn': 1, 'mon_thousands_sep': '.', 'negative_sign': '-', 'currency_symbol': 'Eu', 'n_sep_by_space': 0, 'mon_grouping': [3, 3, 0], 'p_cs_precedes': 1, 'positive_sign': '', 'grouping': [127]}

What does the number 127 mean?

Am 12.01.2013 um 12:39 schrieb Stefan Krah <report@bugs.python.org>:

> 
> Stefan Krah added the comment:
> 
> What is the output of this?
> 
>>>> locale.localeconv()                     
> {'mon_decimal_point': ',', 'frac_digits': 2, 'p_sign_posn': 1, 'thousands_sep': '.', 'p_sep_by_space': 1, 'int_curr_symbol': 'EUR ', 'decimal_point': ',', 'mon_thousands_sep': '.', 'n_sep_by_space': 1, 'int_frac_digits': 2, 'currency_symbol': 'EUR', 'negative_sign': '-', 'mon_grouping': [3, 3, 0], 'positive_sign': '', 'n_cs_precedes': 0, 'grouping': [3, 3, 0], 'n_sign_posn': 1, 'p_cs_precedes': 0}
> 
> 
> If 'grouping' is [], then this looks like a bug in OSX. Python gets
> the values directly from the operating system.
> 
> ----------
> nosy: +skrah
> status: open -> pending
> 
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue16944>
> _______________________________________
msg179789 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2013-01-12 12:24
127 means "no-more-grouping", so Python behaves as instructed by the OS.

As you see, the OS prescribes 1.345.677,222 for *monetary* quantities
and 1345677,222 otherwise.

According to  http://de.wikipedia.org/wiki/DIN_1333 , for non monetary
quantities DIN-1333 says *empty spaces* *may* be used as separators.
DIN-5008 says they *should* be used. :)


Most operating systems use [3, 3, 0] also for de_DE 'grouping', but
given the unclear situation it's hard to claim a bug in OSX.


The only way out of this would be to introduce a new 'm' locale specifier
that uses mon_grouping.
msg179951 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2013-01-14 16:31
I think this issue should be closed, since we're doing as we're instructed by the OS. If someone wants to open a new issue for the "m" format specifier type, I'd support that.
msg179953 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2013-01-14 16:49
I agree, we can't really do anything here.
History
Date User Action Args
2013-01-14 16:49:42skrahsetstatus: open -> closed
resolution: not a bug
messages: + msg179953

stage: resolved
2013-01-14 16:31:00eric.smithsetnosy: + eric.smith
messages: + msg179951
2013-01-12 12:24:29skrahsetnosy: + mark.dickinson
messages: + msg179789
2013-01-12 11:52:17Peter.Stahlsetstatus: pending -> open

messages: + msg179788
2013-01-12 11:39:14skrahsetstatus: open -> pending
nosy: + skrah
messages: + msg179787

2013-01-12 11:26:56Peter.Stahlcreate