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)
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 3, 2012 at 19:46
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? Commented 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.

answered Jan 3, 2012 at 21:03
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 []. Commented 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

answered Jan 3, 2012 at 20:38
2
  • crisscrossed with your edit. oops Commented 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. Commented 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.

answered Jan 3, 2012 at 20:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.