title: How to convert float to fixed point decimal in python
body: <p>I have some library function <code>foo</code>, that returns a floating point value with two decimal places (representing a price). I have to pass to to other function <code>bar</code> which expects a Decimal with fixed point for two decimal places.</p>
  
  <pre><code>value = foo() # say value is 50.15
  decimal_value = decimal.Decimal(value) # Not expected. decimal_value contains Decimal('50.14999999999999857891452847979962825775146484375')
  bar(decimal_value) # Will not work as expected
  
  # One possible solution
  value = foo() # say value is 50.15
  decimal_value = decimal.Decimal(str(round(value,2))) # Now decimal_value contains Decimal('50.15') as expected
  bar(decimal_value) # Will work as expected
  </code></pre>
  
  <h3>Question:</h3>
  
  <p>How to convert arbitrary float to fixed Decimal point with 2 decimal places? And without intermediate string conversion using <code>str</code>.</p>
  
  <p>I am not worried about the performance. Just want to confirm if intermediate str conversion is the pythonic way.</p>
  
  <h3>Update: Other Possible Solutions</h3>
  
  <pre><code># From selected answer
  v = 50.15
  d = Decimal(v).quantize(Decimal('1.00'))
  
  # Using round (Does not work in python2)
  d = round(Decimal(v), 2)
  </code></pre>