1

I have a featureclass (in a File Geodatabase), with a particular field of type Double. I want to copy it over to a text field, so that only 3 decimal places are shown.

For example: 34.78902345 becomes 34.789

I have gone through this question: How to convert a double field to a string?, but that does not solve my issue. I have even tried to format the double field, but even then the text field contains all the decimals.

How do I do this in ArcGIS 10.0?

4

You should be able to use string formatting:

'{0:.3f}'.format(your_floating_point_value)

Example:

>>> '{0:.3f}'.format(34.78902345)
'34.789'

Here is the Python string formatting cookbook for reference.

To use this in the field calculator you can create a function:

def my_format(val):
  return '{0:.3f}'.format(val)
2

You can use this python function within Field Calculator:

def updateValue(value):
  if value <> '':
    newValue = str(value)
    splitBefore = newValue.split('.')[0]
    splitAfter = newValue.split('.')[1]
    return splitBefore + '.' + splitAfter[:3]
  else: return ''

Name =

updateValue( !yourFieldName!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.