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>>>> x = 3.5666666<br>>>> x = round(x,3)<br>
>>> 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. >>> from decimal import *<br>>>> getcontext().prec = 3<br>>>> x = decimal(3.456654)<br><br>>>> x = Decimal('3.2213333')<br>>>> x<br>Decimal('3.2213333')<br>
>>> getcontext().prec = 5<br>>>> x<br>Decimal('3.2213333')<br>>>> y = round(x,3)<br>>>> y<br>3.2210000000000001<br>>>> x = 3.223344<br>>>> z = round(x,3)<br>>>> z<br>
3.2229999999999999<br>