[Django]-Python: Access Posix' locale database without setlocale()

3👍

The magic library to achieve this is called Babel. Does what I want:

Before

import locale
setlocale(LC_ALL, 'de')
x = locale.format('%.2f', 123)
setlocale(LC_ALL, '')

After

from babel.numbers import format_decimal
x = format_decimal(123, format='#0.00', locale='de')

…and has a good Djang integration gratis.

Leave a comment