how does one round off a float number in python? i have tried this using two ways but have been unsuccessful so far:<br><br>1. IDLE 2.6.6      ==== No Subprocess ====<br>&gt;&gt;&gt; x = 3.5666666<br>&gt;&gt;&gt; x = round(x,3)<br>
&gt;&gt;&gt; x<br>3.5670000000000002<br><br>[ The above works when i try doing x = round(x,2). I am working on a windows machine. The above seems to work on the linux machine of a colleague but he gets the same problem when he tries x = round(x,4)]<br>
<br>2. &gt;&gt;&gt; from decimal import *<br>&gt;&gt;&gt; getcontext().prec = 3<br>&gt;&gt;&gt; x = decimal(3.456654)<br><br>&gt;&gt;&gt; x = Decimal(&#39;3.2213333&#39;)<br>&gt;&gt;&gt; x<br>Decimal(&#39;3.2213333&#39;)<br>
&gt;&gt;&gt; getcontext().prec = 5<br>&gt;&gt;&gt; x<br>Decimal(&#39;3.2213333&#39;)<br>&gt;&gt;&gt; y = round(x,3)<br>&gt;&gt;&gt; y<br>3.2210000000000001<br>&gt;&gt;&gt; x = 3.223344<br>&gt;&gt;&gt; z = round(x,3)<br>&gt;&gt;&gt; z<br>
3.2229999999999999<br>