Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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!)
share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
that did it, thanks! –  IanS May 14 at 15:21
    
Nice, don't forget to accept the answers on your questions! –  Alex Tereshenkov May 14 at 15:25

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

0 if round(!FieldA!,1) == round(!FieldB!,1) else 1
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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