1

With older versions of ArcMap (9.3, 9.2, etc) I was always able to round numbers down to 2 decimal places using field calculator even if that field had both numeric values and a bunch of NULL values. It used to just ignore the NULL values. With ArcGIS 10.x this is no longer the case.

round([UPSTREAMINVERT],2)

Rounding a field that has any NULL values leads to error 999999, error executing function - invalid use of Null: 'round'

I realize it works just fine when you remove NULL values from the selection. However, I'd prefer not to have to do this for every field I'd like to have rounded.

Has anyone else experienced this and found a work-around? I've tried to do an if-then statement in field calculator to only return the rounded value if the value is not NULL. This gives the same error message.

Thanks.

5
  • can you post your calculator expression?
    – vinayan
    Commented Sep 20, 2012 at 16:59
  • round([UPSTREAMINVERT],2)
    – Rayner
    Commented Sep 20, 2012 at 17:00
  • If your feature class is in an enterprise geodatabase that supports precision and scale you could set its scale to 2 and the database would automatically round it to two decimal places. File geodatabases do not support precision/scale, however! See also: gis.stackexchange.com/questions/28695/…
    – blah238
    Commented Sep 20, 2012 at 17:18
  • 1
    It also gives an error in 10.0. Commented Sep 20, 2012 at 19:12
  • Thanks Rayner. round([UPSTREAMINVERT],2) this helped me.
    – vadivelan
    Commented Feb 28, 2014 at 17:25

2 Answers 2

2

I think python uses None instead of Null as in other languages..It Could be the issue. You could do a check if

fieldValue is None

before rounding.

1
  • Or just use round([UPSTREAMINVERT] or 0.0,2) as your expression Commented Sep 20, 2012 at 21:09
0

I always find the syntax in the field calculator really tricky, with the lack of syntax highlighting and fixed width fonts a real problem. In order to skip over the null values that are causing you problems, just use python's terse conditionals, thereby avoiding the need to use code like NOT NULL or one of the many other variants that exist in various languages.

In the Pre-Logic Script Code box:

def rounder(UPSTREAMINVERT):
 if UPSTREAMINVERT:
  #do the rounding as normal
 else:
  #return a 0 or whatever is appropriate to you

And in the second box simply call this function:

rounder(!UPSTREAMINVERT!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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