Determining the value of a position on an array based on its nearest datapoint known value
This is an application of rounding.

idx = int(round(float(pos) / step)) - 1


Note, however, that the result in case pos is exactly halfway into a step is different from your code, and also differs between Python versions.