Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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)
share|improve this answer

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!)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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