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.

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.

share|improve this question
    
can you post your calculator expression? –  vinayan Sep 20 '12 at 16:59
    
round([UPSTREAMINVERT],2) –  Rayner Sep 20 '12 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 Sep 20 '12 at 17:18
1  
It also gives an error in 10.0. –  Jakub Sep 20 '12 at 19:12
    
Thanks. I updated the question to reflect this. –  Rayner Sep 20 '12 at 20:20

2 Answers 2

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

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.

share|improve this answer
    
Or just use round([UPSTREAMINVERT] or 0.0,2) as your expression –  Jason Scheirer Sep 20 '12 at 21:09

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.