1

If I open the 'Region and language' dialog, I have 'Formats' set to 'Germany'. If I click that setting, the 'Numbers' preview is '123.456.789,00' (comma as a decimal separator).

But if I run python3 -c 'import locale; print(locale.localeconv()["decimal_point"])', it outputs . (a dot, not a comma).

How can I get the decimal point as configured by the user in the 'Region and language' dialog?

wjandrea
  • 14,109
  • 4
  • 48
  • 98
Janus Troelsen
  • 2,668
  • 23
  • 24

1 Answers1

1

You need to run locale.setlocale() too.

python3 -c 'import locale; locale.setlocale(locale.LC_ALL, ""); print(locale.localeconv()["decimal_point"])'
Gunnar Hjalmarsson
  • 32,938
  • 3
  • 63
  • 94
  • This simply adopts whatever is in `LC_ALL`. On my system, somehow all the variables reported by `locale` are not de_DE even though Germany is selected as mentioned. – Janus Troelsen Nov 26 '18 at 20:31
  • 1
    @JanusTroelsen: No, it imports all the locale categories which are currently effective (i.e. in accordance with the output of the `locale` command). If you switched to German as Format in the current session, you need to relogin to have the `LC_NUMERIC` variable (which affects the decimal separator) updated. – Gunnar Hjalmarsson Nov 26 '18 at 21:00