HOW TO

Format a number field to a text field with currency formatting

Last Published: April 26, 2020

Summary

When formatting a number field to display as currency, only the value displays in the Table view.

To use currency formatting for analysis, annotations, and so forth, the values must be formatted in a text field. The instructions provide a sample code to convert a number field to a text field with currency formatting. For example, '1500000.30' converts to '$1,500,000.30'.

Procedure



  1. Add a text field to the feature class.
  2. Right-click the new text field > Field Calculator.
  3. Select the Python parser, and type the following code in the code block.

    Code:
    '$' + '{:,}'.format( !Currency_Field! )


    Note:
    Make sure to change !Currency_Field! to the name of the field that has the currency values.

  4. To round values, check the dialog "Show Codeblock" and type the following code into the Pre-Logic Script Code window.

    Code:
    def currency(x):
    val = round(x,2)
    out = '$' + '{:,}'.format(val)
    right = len(out.split('.')[1])
    if right < 2:
    return out + '0'
    else:
    return out


    Paste the following code (and change the name of the field in the code to the field being converted) in the bottom window.

    Code:
    currency( !Currency_Field! )

Article ID: 000012384

Software:
  • ArcMap

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options