'Proper' rounding in Python, to 3 decimal places
<p>I may be missing something essential, but I can't figure out a way to 'properly' round floats/Decimals in Python (2.7), at least to three decimal places.  By 'properly' I mean that 1.2225 should round to 1.223, and 1.2224 should round to 1.222.  </p>

<p>I know <code>round</code> won't work for floats in Python, by design, but I can't seem to get <code>Decimal</code> to behave as expected, nor the <code>ceil</code> function.  Looking for built-in functionality rather than custom function workarounds preferably, but open to both.</p>

<pre><code>&gt;&gt;&gt; x = 1.2225                                   # expected: 1.223
&gt;&gt;&gt; round(x, 3)               
1.222                                            # incorrect

&gt;&gt;&gt; from math import ceil

&gt;&gt;&gt; ceil(x * 1000.0) / 1000.0
1.223                                            # correct
&gt;&gt;&gt; y = 1.2224                                   # expected: 1.222
&gt;&gt;&gt; ceil(y * 1000.0) / 1000.0 
1.223                                            # incorrect

&gt;&gt;&gt; from decimal import Decimal, ROUND_UP, ROUND_HALF_UP

&gt;&gt;&gt; x = Decimal(1.2225)
&gt;&gt;&gt; x.quantize(Decimal('0.001'), ROUND_UP)
Decimal('1.223')                                 # correct
&gt;&gt;&gt; y = Decimal(1.2224)
&gt;&gt;&gt; y.quantize(Decimal('0.001'), ROUND_UP)
Decimal('1.223')                                 # incorrect

&gt;&gt;&gt; y.quantize(Decimal('0.001'), ROUND_HALF_UP)
Decimal('1.222')                                 # correct
&gt;&gt;&gt; x.quantize(Decimal('0.001'), ROUND_HALF_UP)
Decimal('1.222')                                 # incorrect
</code></pre>

<p>Is there a way to get the desired result?</p>