On 19 September 2012 19:27, Andrew Tritt <span dir="ltr"><<a href="mailto:ajtritt@lbl.gov" target="_blank">ajtritt@lbl.gov</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Hello,</div><div><br></div><div>I am new to python, and I was experimenting with the round function, and came across what appears to be a bug in floating point rounding. I am guessing there is a valid explanation for it. </div>

<div><br></div><div>When I round the floating points 10.6[0-9]5 to two decimal places, it rounds as expected for 6 of the 10, but not for the other 4. When I try the same for 10.7[0-9]5, I experience the same problem, but for 5 of the 10 possibilties, and not for the analogous floats.</div>

<div><br></div><div>Also, python storing the numbers as they are represented at the prompt. i.e. 10.665 is stored as 10.665, not something like 10.665000001 or 10.66499999999.</div><div><br></div><div>Can anyone explain to me what's happening? </div>
</blockquote><div><br></div><div>It is because Python (like all programming languages I know) represents floating point numbers in base 2. This is discussed in the <a href="http://python.org">python.org</a> tutorial:</div>
<div><a href="http://docs.python.org/tutorial/floatingpoint.html">http://docs.python.org/tutorial/floatingpoint.html</a></div><div><br></div><div>Oscar</div></div>