0

I am running into a formatting / precision issue which I'm hoping to control

I obtain a list of numbers such as:

x = [0.009947, 0.009447, 0.008947]

The finished product I'm after is a DataFrame with a column whose value is this list but multiplied by 100 with 3 decimal places, e.g.

[0.995, 0.945, 0.895]

I proceed as follows:

x = 100*np.around([0.009947, 0.009447, 0.008947],5)

this displays as

array([0.995, 0.945, 0.895])

When I build the DataFrame:

pd.DataFrame({'test':[x]})

I get for the value in the 'test' column:

[0.9950000000000001, 0.9450000000000001, 0.895]

This does not happen in other examples and I'm not sure how to control the behavior. Appreciate any suggestions

laszlopanaflex
  • 1,836
  • 3
  • 23
  • 34
  • Does this answer your question? [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – DYZ Oct 11 '20 at 00:18

1 Answers1

0

This is a general issue with the usage of floating points in computers, check this out from the docs

Jimmar
  • 4,194
  • 2
  • 28
  • 43