1

In numpy, some digits "finishing by 5" are rounding up and down. For instance:

import numpy as np
np.array([0.025, 0.015]).round(2)
# array([0.02, 0.02])

Here 0.015 rounds up to 0.02 which is what I expect, but 0.025 rounds down to 0.02 instead of 0.03, why so ?

Is it possible to fix that ? (Except using an epsilon for comparing float values)

BlueSheepToken
  • 5,751
  • 3
  • 17
  • 42
  • 3
    See the doc on [`np.around`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.around.html): _For values exactly halfway between rounded decimal values, NumPy rounds to the nearest even value. Thus 1.5 and 2.5 round to 2.0, -0.5 and 0.5 round to 0.0, etc. Results may also be surprising due to the inexact representation of decimal fractions in the IEEE floating point standard [1] and errors introduced when scaling by powers of ten._ – HansHirse Jan 27 '20 at 11:16
  • Thank you @HansHirse. Should I delete my question ? – BlueSheepToken Jan 27 '20 at 11:17

0 Answers0