title: Format numbers as currency in Python
body: <p>I learn from <a href="https://stackoverflow.com/questions/320929/currency-formatting-in-python">Currency formatting in Python</a>, use the <a href="https://docs.python.org/2/library/locale.html" rel="noreferrer">locale</a> module to format numbers as currency. For instance,</p>
  
  <pre><code>#! /usr/bin/env python
  # -*- coding: utf-8 -*-
  
  import locale
  
  value = 123456789
  
  l = locale.setlocale(locale.LC_ALL, '')     # LC_CTYPE=en_US.UTF-8;LC_NUMERIC=fr_FR.UTF-8;LC_TIME=fr_FR.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=fr_FR.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=fr_FR.UTF-8;LC_NAME=fr_FR.UTF-8;LC_ADDRESS=fr_FR.UTF-8;LC_TELEPHONE=fr_FR.UTF-8;LC_MEASUREMENT=fr_FR.UTF-8;LC_IDENTIFICATION=fr_FR.UTF-8
  s = locale.currency(value, grouping=True)   # 123 456 789,00 €
  
  locale.setlocale(locale.LC_ALL, 'en_US.utf-8') 
  s = locale.currency(value, grouping=True)   # $123,456,789.00
  
  locale.setlocale(locale.LC_ALL, 'en_US')    # WHY? locale.Error: unsupported locale setting
  s = locale.currency(value, grouping=True)
  </code></pre>
  
  <p>I'd like to format numbers to other currency, say <code>de_DE</code>. I encounter the issue <code>locale.Error: unsupported locale setting</code> since the locale <code>de_DE</code> is not in the list of <code>locale -a</code>.</p>
  
  <pre><code>locale.setlocale(locale.LC_ALL, 'de_DE')        # locale.Error: unsupported locale setting
  s = locale.currency(value, grouping=True)
  </code></pre>
  
  <p>One solution is to add this locale to my machine. Is there a better way?</p>