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,136
  • 29
  • 109
  • 338
jsmith
  • 741
  • 2
  • 8
  • 19
  • 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 03 '12 at 20:04

3 Answers3

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.

Patty Jula
  • 1,083
  • 2
  • 12
  • 29
  • 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 03 '12 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

Brad Nesom
  • 17,412
  • 2
  • 42
  • 68
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.

Chad Cooper
  • 12,714
  • 4
  • 46
  • 87