title: How to get a list of decimals in python 3
body: <p>No, this is not a duplicate and the link above is specifically what I was referring to as not the correct answer.  That link, and my post here specifically ask about producing a Decimal list.  But the "answer" produces a float list.</p>
  
  <p>The correct answer is to use Decimal parameters with np.arange as in 
  `x_values = np.arange(Decimal(-2.0), Decimal(2.0), Decimal(0.1))  Thanks <a href="https://stackoverflow.com/users/2084384/boargules">https://stackoverflow.com/users/2084384/boargules</a></p>
  
  <p>I believe this may be answered elsewhere, but the answers I've found seem wrong.  I want a list of decimals (precision = 1 decimal place) from -2 to 2.
  -2, -1.9, -1.8 ... 1.8, 1.9, 2.0</p>
  
  <p>When I do:</p>
  
  <pre><code>import numpy as np
  x_values = np.arange(-2,2,0.1)
  x_values
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>array([ -2.00000000e+00,  -1.90000000e+00,  -1.80000000e+00, ...
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>from decimal import getcontext, Decimal
  
  getcontext().prec = 2
  x_values = [x for x in np.around(np.arange(-2, 2, .1), 2)]
  x_values2 = [Decimal(x) for x in x_values]
  x_values2
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>[Decimal('-2'),
   Decimal('-1.899999999999999911182158029987476766109466552734375'),
   Decimal('-1.8000000000000000444089209850062616169452667236328125'), ...
  </code></pre>
  
  <p>I'm running 3.6.3 in jupyter notebook.</p>
  
  <p>Update:  I changed the ranges from 2 to 2.0.  This improved the result, but I still get a rounding error:</p>
  
  <pre><code>import numpy as np
  x_values = np.arange(-2.0, 2.0, 0.1)
  x_values
  </code></pre>
  
  <p>Which produces:</p>
  
  <pre><code>-2.00000000e+00,  -1.90000000e+00,  -1.80000000e+00, ...
   1.00000000e-01,   1.77635684e-15,   1.00000000e-01, ...
   1.80000000e+00,   1.90000000e+00
  </code></pre>
  
  <p>Note 1.77635684e-15 may be an incredibly small number, but it's NOT zero.  A test for zero will fail.  Therefore the output is wrong.</p>
  
  <p>My response to the duplicate assertion.  As you can see by my results the answer at <a href="https://stackoverflow.com/questions/477486/how-to-use-a-decimal-range-step-value">How to use a decimal range() step value?</a> does not produce the same results I'm seeing with a different range. Specifically floats are still being returned and not rounded and 1.77635684e-15 is not equal to zero.</p>