title: Is there a simple and preferred way of German number string formatting in Python?
body: <p>I am searching for the proper way of German number formatting (e.g. <code>1.000,1234</code>) in Python under Windows OS. </p>
  
  <p>I tried <code>locale.setlocale</code> but did not succeed.</p>
  
  <p>Instead, I have written a function to come up with the desired output.</p>
  
  <p>Is there a better way?</p>
  
  <pre><code>def ger_num(number, precision=3):
      """
      returns german formatted number as string or an empty string
      """
      if number is not None:
          try:
              my_number = "{:,f}".format(number)
          except ValueError:
              return ""
  
          decimals, fraction = my_number.split(".")[0], my_number.split(".")[1]
          decimals = decimals.replace(",", ".")
  
          if precision:
              return decimals + "," + fraction[:precision]
          else:
              return decimals
  
      else:
          return ""
  </code></pre>