Round values in an attribute table to the nearest nth value using the Field Calculator and a Python expression.

2745
4
Jump to solution
03-01-2016 10:19 PM
KelvinMwakomo
Occasional Contributor

Hello guys

I want to use the Field Calculator in ArcMap to round an existing column to two decimals. Currently I have a column (AREA_Ha) that is 3 decimal places long and would like to simply round it down to 2 decimals.

sreen.JPG

I have tried this ( round(!AREA_Ha!, 2)) but get this error message " There was a failure during processing, check the Geoprocessing Results window for details.

sreen1.JPG

Your help please.

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

str(round(float(a.split(" ")[0]),2) ) + " ha"

but it is getting ridiculously convoluted, the area calculation should have been sent to a numeric field, rounding there, and then, converted to string in a subsequent field

View solution in original post

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

that is because your area field was made into a string.

You can tell because it is left justified and contains 'ha' at the end. So however you created the area field wasn't a true area field but the representation of an area field.

The most descriptive is to follow

a = '1.2345 ha'

round(float(a.split(" ")[0]),2)

yields 1.23

where 'a' is your field name

KelvinMwakomo
Occasional Contributor

Thanks Dan but is to possible to add the unit abbreviation eg.1.23 Ha

0 Kudos
DanPatterson_Retired
MVP Emeritus

str(round(float(a.split(" ")[0]),2) ) + " ha"

but it is getting ridiculously convoluted, the area calculation should have been sent to a numeric field, rounding there, and then, converted to string in a subsequent field

0 Kudos
KelvinMwakomo
Occasional Contributor

Thanks Dan for your assistance