[Numpy-discussion] Precision in Python

Charles R Harris charlesr.harris at gmail.com
Tue Dec 5 12:39:49 CST 2006


On 11/27/06, Elton Mendes <emgmendes at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20061205/9a6a794c/attachment.html 


More information about the Numpy-discussion mailing list