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?

1

You need to run locale.setlocale() too.

python3 -c 'import locale; locale.setlocale(locale.LC_ALL, ""); print(locale.localeconv()["decimal_point"])'
  • 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
  • @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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.