# How to make Field Value constant size(length) by appending zeros towards the end?

I have been racking my brain, but I can't seem to find a solution to appending my field values in my .dbf to correspond with the values of my feature's attribute table. All I need to do is to append 0's to the field value if the field value is less than 11 characters in length. It needs to be done in the field calculator through VB Script or Python.

-
Can you give more details please? are the 0s to be added in front or behind the numbers? Why are you referring to dbf files if you want to work in field calculator? Do you want the new values to be strings or integers? –  sgrieve Dec 3 '12 at 10:07

You have several options in python: zfill, interpolation operator ('%'), and rjust (pad with any character...not just zeros). See this SO question: http://stackoverflow.com/questions/339007/python-nicest-way-to-pad-zeroes-to-string

-

Using python's string multiplication, this can be done very simply in a couple of lines. The only tricky bit is that you must convert an int to a string in order to use the `len()` function.

Assuming the field you are working with is called `x`:

``````def pad(x):
if len(str(x)) < 11:
return str(x) + ('0'*(11-len(str(x))))
``````

Which can be called with:

``````pad(!x!)
``````
-

possibley this could be a one-liner..but i am not able to figure out for now :)

Pre-Logic Script Code:

``````def AppendZeroes(strContent):
a = len(strContent)
strTemp = ""
if(a < 11):
for i in range(11- a):
strTemp =  strTemp + "0"
strContent = strContent + strTemp
return strContent
``````

call it using

``````AppendZeroes( !YOUR_FIELD_NAME! )
``````
-