0

Why is the value in the float field changed?

>>> t=np.dtype([("",float),("",float),("",float)])
>>> v=np.array((1.1,1.12,1.123),dtype=t)
>>> v
array((1.1000000000000001, 1.1200000000000001, 1.123), 
      dtype=[('f0', '<f8'), ('f1', '<f8'), ('f2', '<f8')])
>>> 

I am using python 2.6 What do i need to do to preserve the value 1.1 and 1.2 ?

JavaPlanet
  • 83
  • 9
  • python 3.6 gives the correct output >>> t=np.dtype([('',float),('',float),("",float)]) >>> v=np.array([(1.1,1.12,1.123)],dtype=t) >>> v array([(1.1, 1.12, 1.123)], dtype=[('f0', ' – JavaPlanet Jul 26 '19 at 21:14
  • 2
    Possible duplicate of [Python float - str - float weirdness](https://stackoverflow.com/questions/1778368/python-float-str-float-weirdness) – Masoud Jul 26 '19 at 21:15

0 Answers0