How do I convert number field to string field?

3885
4
Jump to solution
04-10-2019 06:53 PM
MichaelHodnett1
New Contributor II

In ArcGIS Pro 2.2.4, I have a file geodatabase feature table where the ZIP code was imported as a long named "ZIP."  I need it to be a string to 1) preserve leading zeroes and 2) join with another table on the ZIP field.

I opened the attribute table and added a new field called "ZIPText" of type String.  I open Calculate Field and using Python 3, try to define ZIPText as !ZIP!.asString()

The expression validates, but when I run it, I get 

ERROR 000539 File "<expression>", line 1

          94501.asString()

with the carat pointing at the "g" at the end of asString.

I've tried other expressions, but my Python is of the "google and try it variety" and Google's out of options. 

Any ideas?

1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

python parser...

str(!ZIP!)

and make sure the destination field is indeed text...

View solution in original post

4 Replies
DanPatterson_Retired
MVP Esteemed Contributor

python parser...

str(!ZIP!)

and make sure the destination field is indeed text...

View solution in original post

MichaelHodnett1
New Contributor II

Ha! I knew it would be something that simple. It works perfectly.  Thank you sir.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Since ZIPs are currently stored as long, there won't be any leading zeroes to preserve.  If you want to create them, you can use Python string formatting:

"{:0>5}".format(!ZIP!)
MichaelHodnett1
New Contributor II

Thank you!  I had intended to add the leading zeroes manually since there aren't that many, but this is a much better way.

0 Kudos