I am trying to truncate (by two decimal places) an array of floats in a numpy array. I do this by doing the following to each element:
np.trunc(100 * i) / 100
However, due to some floating point problems in python, sometimes this formula above does not work. Take for example -2.01 * 100 = -200.99999999999997. Thus, the np.trunc(100 * -2.01) / 100 will not work. it will output -2.00.
Is there a better way to truncate two decimal places in python using np.trunc? Without np.trunc?
Thank you!