title: Python: unusual result with rounding numbers. Is this a quirk that can be fixed?
body: <p>I'm trying to round in Python, but I can't get the correct result each time, which should be</p>
  
  <p>[3.24, -0.16, 0.24, 0.36]</p>
  
  <p><strong>First</strong>, I used <code>round(number, 2)</code> </p>
  
  <blockquote>
    <p>[3.24, -0.16000000000000003, 0.24, 0.36]</p>
  </blockquote>
  
  <p>The second number in the list is not rounded whatsoever...</p>
  
  <p><strong>Then</strong>, I used <code>decimal</code></p>
  
  <pre><code>from decimal import *
  getcontext().prec = 2
  </code></pre>
  
  <blockquote>
    <p>[Decimal('3.2'), Decimal('-0.16'), Decimal('0.24'), Decimal('0.36')]</p>
  </blockquote>
  
  <p>This fixes the original errant number, but now the <em>first</em> number in the list is  not rounded correctly, it should be <code>3.24</code>.</p>
  
  <p>So, I tried a precision of three out of curiosity to see what happens</p>
  
  <pre><code>from decimal import *
  getcontext().prec = 3
  </code></pre>
  
  <blockquote>
    <p>[Decimal('3.24'), Decimal('-0.160'), Decimal('0.240'),
    Decimal('0.360')]</p>
  </blockquote>
  
  <p>... now the first item in the list is doing in three-digit precision what it was supposed to do with two-digit precision.</p>
  
  <p>So I tried, based on another answer, to use <code>math.ceil</code></p>
  
  <pre><code>  math.ceil(number*100)/100 for number in list_of_numbers]
  </code></pre>
  
  <blockquote>
    <p>[3.24, -0.16, 0.25, 0.37]</p>
  </blockquote>
  
  <p>Now the first two numbers in the list are perfect, but the last two numbers in the list, which were supposed to be <code>24</code> and <code>36</code>, are now <code>25</code> and <code>37</code>.</p>
  
  <p>Is it a fool's errand to try and get them all to be exactly right at the same time? </p>
  
  <p><strong>Edit due being marked as duplicate</strong></p>
  
  <p><em>I'm asking if there's a fix for this. It's not just a question on Python and its quirks.
  I've seen other answers and they say use decimal, which doesn't work for me, or to format it and output it as a string, but I don't want a string, I need to use these numbers further, as numbers.</em></p>