<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Field calculator make 4 digit numbers in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356338#M28014</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This could be made into a field calculator expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PaddingStringsDemo.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;vals = [1,10,100,1000]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for i in vals:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; out = "%08.2f" % (i)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; print str(out)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And this is the output...you will note it is a string representation of the number.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;00001.00&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;00010.00&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;00100.00&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01000.00&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Jul 2013 22:21:32 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2013-07-08T22:21:32Z</dc:date>
    <item>
      <title>Field calculator make 4 digit numbers</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356333#M28009</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have object with a number from 1 to 1500.&amp;nbsp; I need to concatenate with another field but need all numbers to be 7 digits.&amp;nbsp; Field 1 is done and contains 3 numbers.&amp;nbsp; I need to add the object number field but have it as xxx0001 through xxx1500.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 13:05:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356333#M28009</guid>
      <dc:creator>BobbySells</dc:creator>
      <dc:date>2013-07-08T13:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator make 4 digit numbers</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356334#M28010</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is what I have tried but of course errors.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def strID():&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IF [ObjNum]&amp;lt;10&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;then strID()="100000"&amp;amp; [ObjNum]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;elseif&amp;nbsp; [ObjNum]&amp;lt;100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;then strID()="10000"&amp;amp; [ObjNum]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;elseif&amp;nbsp; [ObjNum]&amp;lt;1000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;then strID()="1000"&amp;amp; [ObjNum]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;elseif&amp;nbsp; [ObjNum]&amp;lt;10000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;then strID()="100"&amp;amp; [ObjNum]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end if&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 14:18:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356334#M28010</guid>
      <dc:creator>BobbySells</dc:creator>
      <dc:date>2013-07-08T14:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator make 4 digit numbers</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356335#M28011</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Pre-logic:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def concatFields( field1, field2 ): &amp;nbsp; digits = str(field1)[-4:] &amp;nbsp; code = str(field2) &amp;nbsp; return int(code + digits)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;concatFields( !ObjectNums!, !Field1!)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had mine set up where the "field1" parameter is the 7 digit object numbers and "field2" is your 3 digit code.&amp;nbsp; This worked for me.&amp;nbsp; Be sure to set the parser to Python.&amp;nbsp; See attached screenshots:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]25790[/ATTACH][ATTACH=CONFIG]25791[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 14:35:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356335#M28011</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-07-08T14:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator make 4 digit numbers</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356336#M28012</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This should also work. "field1" would be the Object ID and "field2" would be the 3 digit number. create a new Text field then run. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Pre-Logic Script Code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def concat(field1, field2):
&amp;nbsp; if field1 &amp;gt;= 0 and field1 &amp;lt; 10:
&amp;nbsp;&amp;nbsp;&amp;nbsp; object = str("000") + str(field1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return str(field2) + str(object)
&amp;nbsp; if OID &amp;gt; 9 and field1 &amp;lt; 100:
&amp;nbsp;&amp;nbsp;&amp;nbsp; object = str("00") + str(field1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return str(field2) + str(object)
&amp;nbsp; if OID &amp;gt; 99 and field1 &amp;lt; 1000:
&amp;nbsp;&amp;nbsp;&amp;nbsp; object = str("0") + str(field1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return str( field2) + str(object)
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; object = str(field1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; str(field2) + str(object)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Field = &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
concat( !FID!, !digit! )
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:40:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356336#M28012</guid>
      <dc:creator>PhillipCobb</dc:creator>
      <dc:date>2021-12-11T16:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator make 4 digit numbers</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356337#M28013</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can also use Python zero fill string operator. It adds a defined number of zeros to the start of a string. You can use it like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def concatFields(Field1, ObjNum):
&amp;nbsp; prefix = str(Field1)
&amp;nbsp; suffix = str(ObjNum).zfill(4)
&amp;nbsp; return int(prefix + suffix)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:40:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356337#M28013</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T16:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator make 4 digit numbers</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356338#M28014</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This could be made into a field calculator expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PaddingStringsDemo.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;vals = [1,10,100,1000]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for i in vals:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; out = "%08.2f" % (i)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; print str(out)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And this is the output...you will note it is a string representation of the number.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;00001.00&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;00010.00&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;00100.00&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;01000.00&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 22:21:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356338#M28014</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-07-08T22:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator make 4 digit numbers</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356339#M28015</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think I misunderstood the original question; both Dan and Stacy have provided better answers.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2013 23:46:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-make-4-digit-numbers/m-p/356339#M28015</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-07-08T23:46:35Z</dc:date>
    </item>
  </channel>
</rss>

