18

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)
1
  • 2
    An 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
    Jan 3, 2012 at 20:04

3 Answers 3

14

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.

1
  • 1
    Yup, 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
    Jan 3, 2012 at 21:40
12

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

2
  • crisscrossed with your edit. oops
    – Brad Nesom
    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
    Jan 3, 2012 at 20:49
5

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.

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.