This is a floating point rounding error due to the colon-generated vector.
As Rasman said, if you do this:
floor((0.1:0.1:2 + eps) / 0.01)
No rounding errors.
However, based on how the colon operator works , I suggest doing the same calculation as follows:
floor([(1:20)/10] / 0.01)
[ Edit : after Rasman's comment, Iβll add that the latter approach also works for negative values, and sometimes eps
added)
The bottom line is that itβs best to use a colon operator with integers to minimize rounding errors.
source share