I have a field entitled "Lung_lunc". It contains some "0" values and the rest are values > 0. I want to turn those "0" values, into "0.0001". I have added a new field: "Lung_lunca", and I want to use a IF statement in Field calculator, to do so. I have tried the version in the image, but when I run the script, nothing changes (the values remain the same, as in the previous field). I have looked over similar questions here, but did not manage to find a solution.

How should I modify the script, in order to work?

P.S. I have made sure that both "Lung_lunc" and "Lung_lunca" are double fields, so they accept decimals.

Field calculator

  • Yes, but there are 2 fields: "Lung_lunc" and "Lung_lunca".. – Andrei Apr 20 '15 at 22:05
  • Are you completely sure you don't mean "> 0"? Your expression is correct as far as I can tell. – phloem Apr 20 '15 at 22:17
  • Nothing wrong with your code. Check environment extent, set it to extent of this shapefile – FelixIP Apr 21 '15 at 4:35
  • I have tried both of your suggestions, but it doesn't make any change – Andrei Apr 21 '15 at 12:25

I'm not really familiar with VB, but you could use this Python code:

def check(value):
  if value == 0:
    results = 0.0001
    results = value

  return results

And for the Expression put:


Make sure to change the Expression Type to Python.

  • I tried this code, but the result is that it rounds all my values. It does not fix the issue with the "0" values, but it eliminates all decimals... – Andrei Apr 21 '15 at 12:19
  • Maybe there should be an extra code for specifying the format of the result, to have 5 decimals, let's say? (float or double)? – Andrei Apr 21 '15 at 13:02
  • 2
    Well, what field type is Lung_lunca when you go into it's properties? – ianbroad Apr 21 '15 at 14:06
  • Thank you for the hint! I have changed from "Double" to "float" and then, the code generated the good results! This solved it. – Andrei Apr 22 '15 at 14:49

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.