title: Format Python Decimal object to a specified precision
body: <p>I've spent countless hours researching, reading, testing, and ultimately confused and dismayed at Python's Decimal object's lack of the most fundamental concept: Formatting a Decimal's output to a string.</p>
  
  <p>Let's assume we have some strings or Decimal objects with the following values:</p>
  
  <pre><code>   0.0008
    11.1111
   222.2222
  3333.3333
  1234.5678
  </code></pre>
  
  <p>The goal is to simply set the Decimal's precision to the second decimal place. Eg, <code>11.1111</code> would be formatted as <code>11.11</code>, and <code>1234.5678</code> as <code>1234.57</code>.</p>
  
  <p>I envision code similar to the following:</p>
  
  <pre><code>import decimal
  decimals = [
    decimal.Decimal('0.0008'),
    decimal.Decimal('11.1111'),
    decimal.Decimal('222.2222'),
    decimal.Decimal('3333.3333'),
    decimal.Decimal('1234.5678'),
  ]
  for dec in decimals:
    print dec.as_string(precision=2, rounding=ROUND_HALF_UP)
  </code></pre>
  
  <p>The resulting output would be:</p>
  
  <pre><code>0.00
  11.11
  222.22
  3333.33
  1234.57
  </code></pre>
  
  <p>Obviously we cannot make use of the Decimal's context's precision, because this takes into consideration the TOTAL number of digits, not just decimal precision.</p>
  
  <p>I'm also not interested in converting the Decimal to a float to output its value. The ENTIRE reason behind Decimal is to avoid storing and running calculations on floats.</p>
  
  <p>What other solutions are there? I understand there are many other similar questions on stack overflow, but none of them have I found to resolve the underlying issue I am inquiring of.</p>
  
  <p>Thanks much!</p>