Convert a string field to a numeric field

Last Published: January 13, 2023


In some scenarios, it is necessary to convert a field of string (text) values in an attribute table to numeric values, typically because the original data type was not set or recognized, or so that proper data analysis can be performed. To preserve data integrity (especially if sharing or importing data from outside sources), the method for converting fields to different types is to copy the data to a new field of the desired type.

Two solutions are described below; the first pertains to ArcGIS Pro 1.x and 2.x; the second solution is for ArcGIS Desktop 10.x (ArcMap).


For ArcGIS Pro 1.x and 2.x

  1. Open an ArcGIS Pro project, and add the applicable data or table to the project.
  2. Right-click the data or table in the Contents pane, and select Attribute Table.
  3. Click the Add button to create a new field. an image of the Add button
  4. In the Fields list view, set the following properties:
    1. Set a name for the new field.
    2. Set the Data Type to a numeric type. Long or Double field types are most common.
    3. Set the Number Format to Numeric and adjust the settings as desired.
    4. If necessary, set the domain, default, and length values of the field.
  5. On the top ribbon (of the Fields tab), Save the edits to the table, and close the Fields view.
  6. Right-click the header of the newly created numeric field, and select Calculate Field. The Calculate Field geoprocessing dialog box opens.
  7. The Input Table, Field Name, and Expression Type are automatically filled. In the Expression Fields list window, locate and double-click the string field containing the attributes that must be transferred to the newly created numeric field. The following is entered in the Expression text box:
!<String field name>!
The Calculate Field pane dialog box with the selected string field name.
  1. Click Run to run the tool.
The tool may fail to run if the string field contains Null (empty) values. When creating the new numeric field, ensure the field is nullable to be able to import the Null values from the string field. Refer to the ArcGIS Pro web help document, Add field for more information.

For ArcGIS Desktop 10.x

  1. Open ArcMap, and open the layer or file geodatabase attribute table.
  2. In ArcMap, the data type of the field can be checked by right-clicking the field's header and selecting Properties.
The Field Properties dialog box.
  1. On the top-left of the Table window, click the Table Options drop-down button The Table Options button and select Add Field.
The Add Field option is only available when the user has write access to the data, and the data is not accessed by other users or applications. The option is also disabled when the map is in an edit session.
  1. Provide a Name for the new field.
  2. Set the field Type to a numeric type, such as Long Integer or Double.
  3. Set the Precision and Scale if desired.
  4. Click OK.
  1. Right-click the newly created field's header and select Field Calculator.
  2. If the string field contains only numeric values, use the following steps to copy the attributes to the numeric field:
    1. Set the Parser to VB Script.
    2. Enter [String field name] into the expression window, or select the string field from the Fields box, and click OK.
The Field Calculator dialog box.
  1. If the string field contains mixed alphanumeric and numeric values, use the following steps to copy the attributes:
    1. Set the Parser to VB Script, and check the check box for Show Codeblock.
    2. Copy and paste the code below into the Pre-Logic Script Code text window, and replace 'String field name' with the name of the field to be converted. Leave the left and right brackets:
Dim String, Check
String = [String field name]
Check = IsNumeric(String)
If Check = True then
Output = CDbl(String)
Output = null
End if
In the fifth line, replace 'CDbl(String)' to the following functions, according to the numeric field type selected in Step 3(b):
- Integer: CInt(String)
- Long: CLng(String)
- Double: CDbl(String)
  1. In the second expression window, (in this example, 'DoubleV ='), type:
The image below shows how the Field Calculator dialog box looks. In this example, the string field is converted to a Double field.
The code entered into the Field Calculator window.
  1. Click OK. Once the script is complete, the numeric field is populated with the values from the string field.
If a string field contains values with non-numeric characters or symbols, the value of that cell remains <Null> by default when converting to the numeric field.

Article ID:000002287

  • ArcGIS Pro 1 x
  • ArcMap 10 x
  • ArcGIS Pro 2 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic