2

I am trying to compare 2 fields(double) using python. I want to round to the nearest 10th and flag those with a "1" that are not equal. Here is what I have at the moment:

def Qcontrol(old, new):
  FieldA = math.round(old,1)
  FieldB = math.round(new,1)
  if FieldA == FieldB:
    return 0
  else:
    return 1

Return=
 Qcontrol(!old!, !new!)
3

You just need to remove math. before the round function.

def Qcontrol(old, new):
    FieldA = round(old,1)
    FieldB = round(new,1)
    if FieldA == FieldB:
        return 0
    else:
        return 1

Reference for the built-in function round() in Python.

2

Instead of defining a function, you can do something like this...

0 if round(!FieldA!,1) == round(!FieldB!,1) else 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.