0

I need to compare two float numbers up to 3 decimal places, everything after 3 decimal should be thrown out (do not participate in rounding).

In my function im subtract 0.0005 from each number and then round this numbers via np.around(diff_v, 3), then im check number difference by error value (0.000101)

In some cases it doesn't work the way i expect.

Example

coef = 3

value_error = 0.00101

v1 = 625.016 v2 = 625.015

v1r = 625.016 ( (625.016 - 0.0005) then np.around(625.0155, 3) )

v2r = 625.014 ( (625.015 - 0.0005) then np.around(625.0145, 3) )

v = 625.016 - 625.014 = 0.002 (but original numbers difference is 0.001)

How make this is correct?

My code:

def compare_values(v1, v2, coef):
    v1r = np.around(v1 - rv, coef)
    v2r = np.around(v2 - rv, coef)
    v = np.abs(v1r - v2r)
    return v <= value_error, v

0 Answers0