I want to use the Field Calculator in ArcMap to round an existing column to two decimals. Currently I have a column that is 6 decimal places long and would like to simply round it down to 2 decimals.
I had planned on using the Field Calculator (possibly using Python) to do this, but maybe there is an easier way?
The accepted answer is probably the easiest way to change a single field, however, here is how to do it with the field calculator for both python and VB.
VB:
round([column], 2)
Python:
round(!column!, 2)
-
2An appropriate Field Calculator expression can change the data so that they closely approximate multiples of 0.01. How close depends on how the field is stored; it will differ between floats, doubles, and decimal encoding. (The first two formats cannot exactly store certain values, such as 0.03 = 1.1000001111010111000010100011110...B, which is a repeating infinite binary expression.) Do you perhaps intend to change the field itself so that it accurately stores only decimal numbers with two decimal places?whuber– whuber2012年01月03日 20:04:18 +00:00Commented Jan 3, 2012 at 20:04
3 Answers 3
Have you tried something like what's below in the Field Calculator?
round(!FieldName!, 2)
Make sure you set the Parser to Python in the Field Calculator.
-
1Yup, that's the python way! Apparently it's the exact same thing as the VB way (if you double click on the field to add it). The only difference is ! vs [].jsmith– jsmith2012年01月03日 21:40:50 +00:00Commented Jan 3, 2012 at 21:40
When you go to dispay, calculate or label the field you could just use,
round ([my_field],2)
also to change the field behavior in arcmap...
rounding example
-
crisscrossed with your edit. oopsBrad Nesom– Brad Nesom2012年01月03日 20:42:42 +00:00Commented Jan 3, 2012 at 20:42
-
It's ok, really liked the field behavior bit of knowledge. For what I am doing that would suffice.jsmith– jsmith2012年01月03日 20:49:28 +00:00Commented Jan 3, 2012 at 20:49
Sounds like some simple string formatting would do the trick for you:
>>> "%.2f" % 3.99999
'4.00'
>>>
or, with the number stored in a variable:
>>> j = 3.999999
>>> "%.2f" % j
'4.00'
>>>
This could easily be wrapped up in a Field Calculator function.
Explore related questions
See similar questions with these tags.