Precision in Python
![](https://secure.gravatar.com/avatar/c24bbfda7d3cb8fd2ea2c81226b0d042.jpg?s=120&d=mm&r=g)
Hi. I'm having a precision problem in python Example:
It´s possible to round the number exactly to 5.1
![](https://secure.gravatar.com/avatar/5b2449484c19f8e037c5d9c71e429508.jpg?s=120&d=mm&r=g)
Elton Mendes wrote:
Read this: http://www.python.org/infogami-faq/general/why-are-floating-point-calculatio...
![](https://secure.gravatar.com/avatar/96dd777e397ab128fedab46af97a3a4a.jpg?s=120&d=mm&r=g)
On 11/27/06, Elton Mendes <emgmendes@gmail.com> wrote:
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
![](https://secure.gravatar.com/avatar/5b2449484c19f8e037c5d9c71e429508.jpg?s=120&d=mm&r=g)
Elton Mendes wrote:
Read this: http://www.python.org/infogami-faq/general/why-are-floating-point-calculatio...
![](https://secure.gravatar.com/avatar/96dd777e397ab128fedab46af97a3a4a.jpg?s=120&d=mm&r=g)
On 11/27/06, Elton Mendes <emgmendes@gmail.com> wrote:
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
participants (3)
-
Charles R Harris
-
Elton Mendes
-
Tim Hochberg