On 11/27/06, Elton Mendes <emgmendes@gmail.com> wrote:
Hi.
I'm having a precision problem in python

Example:


>>> a = 5.14343434
>>> b = round(a,1)
>>> b
5.0999999999999996
>>>

Itīs possible to round the number exactly to 5.1

Short answer, no. The number 5.1 can't be exactly represented as a binary fraction, i.e., it can't be expressed in the form int/power_of_two. If all you are worried about is appearance, then the print routine will round it to 5.1 if you restrict the precision of the output. 

Chuck