# Field Calculator: Add “0” to the front of all values in a column

I have a table for each state with Zip Code values. The 5-digit Zip Codes that start with "0" have been reduced to 4-digits. I cannot figure out how to add a "0" to the front of all the values in the table. Tried a number of field-calculations but just can't seem to get it right. Some help please. Using ArcInfo 10.1

-

As far as I know, if you are storing zip codes in a numerical field (integer, float, etc.) it will always strip the preceding zero. The only way I have found to deal with this is to store zip codes in a text column instead.

-

-

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

As Brian mentioned you will need to store the data in a text field. Then the field calculation is: right("00000" + [Existing_ZIP_CODE_FIELD],5)

this will ensure you have all of the necessary leading 0s up to 5 characters.

-
Another way to add leading zeroes is using the `zfill` method on a string: `str(2451).zfill(5)` will result in `"02451"`. – dmahr May 22 '13 at 14:59
And if you want Python code instead of VB Script, use `!Existing_ZIP_CODE_FIELD!.zfill(5)` if existing field is already a string, or `"{:05d}".format(!Existing_ZIP_CODE_FIELD!)` if it's an integer. – nmpeterson May 22 '13 at 15:03

As @Brian has said, the field will have to be text to keep the zero on the left. Here's a quick, basic python example:

``````import arcpy

#add path to shapefile, feature class
fc = "..."

arcpy.AddField_management(fc, "ZIP5", "TEXT", "", "", 5)

rows = arcpy.UpdateCursor(fc)
for row in rows:
#row.ZIP4 should be changed to the field