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.
-
can you post your calculator expression?vinayan– vinayan2012年09月20日 16:59:30 +00:00Commented Sep 20, 2012 at 16:59
-
round([UPSTREAMINVERT],2)Rayner– Rayner2012年09月20日 17:00:09 +00:00Commented 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– blah2382012年09月20日 17:18:52 +00:00Commented Sep 20, 2012 at 17:18
-
1It also gives an error in 10.0.Jakub Sisak GeoGraphics– Jakub Sisak GeoGraphics2012年09月20日 19:12:01 +00:00Commented Sep 20, 2012 at 19:12
-
Thanks Rayner. round([UPSTREAMINVERT],2) this helped me.vadivelan– vadivelan2014年02月28日 17:25:36 +00:00Commented Feb 28, 2014 at 17:25
2 Answers 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.
-
Or just use
round([UPSTREAMINVERT] or 0.0,2)
as your expressionJason Scheirer– Jason Scheirer2012年09月20日 21:09:58 +00:00Commented Sep 20, 2012 at 21:09
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!)