<?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 Format numbers in Field Calc/Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/format-numbers-in-field-calc-python/m-p/307456#M23916</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I am new to python and I am trying to format numbers and concatenate them using python. I basically want to pad numbers with 0s. For example, 5236 should be formatted as 05236 or if it was 300, it should be 00300. I have 4 fields that I want to concatenate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SSN - no formatting&lt;/P&gt;&lt;P&gt;Block - 5 characters&lt;/P&gt;&lt;P&gt;Lot - 4 characters&lt;/P&gt;&lt;P&gt;Qual - 5 characters&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what I have so far, Im not sure why my formatting is not working. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/sad.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;!SSN! + '-' + !BLOCK!.format(00000) + '-' + !LOT!.format(0000) + '-' + !QUAL!.format(00000)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Oct 2015 16:02:28 GMT</pubDate>
    <dc:creator>GeorgePapamihalakis</dc:creator>
    <dc:date>2015-10-13T16:02:28Z</dc:date>
    <item>
      <title>Format numbers in Field Calc/Python</title>
      <link>https://community.esri.com/t5/python-questions/format-numbers-in-field-calc-python/m-p/307456#M23916</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I am new to python and I am trying to format numbers and concatenate them using python. I basically want to pad numbers with 0s. For example, 5236 should be formatted as 05236 or if it was 300, it should be 00300. I have 4 fields that I want to concatenate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SSN - no formatting&lt;/P&gt;&lt;P&gt;Block - 5 characters&lt;/P&gt;&lt;P&gt;Lot - 4 characters&lt;/P&gt;&lt;P&gt;Qual - 5 characters&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what I have so far, Im not sure why my formatting is not working. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/sad.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;!SSN! + '-' + !BLOCK!.format(00000) + '-' + !LOT!.format(0000) + '-' + !QUAL!.format(00000)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2015 16:02:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/format-numbers-in-field-calc-python/m-p/307456#M23916</guid>
      <dc:creator>GeorgePapamihalakis</dc:creator>
      <dc:date>2015-10-13T16:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Format numbers in Field Calc/Python</title>
      <link>https://community.esri.com/t5/python-questions/format-numbers-in-field-calc-python/m-p/307457#M23917</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A tip&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; frmt = "{}-{:0&amp;gt;5}-{:0&amp;gt;4}-{:0&amp;gt;5}".format("abcd",123,456,7890)
&amp;gt;&amp;gt;&amp;gt; print(frmt)
abcd-00123-0456-07890
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;As you see fit...&lt;/P&gt;&lt;P&gt;read the docs&amp;nbsp; &lt;A href="https://docs.python.org/3/library/string.html#formatspec" rel="nofollow noopener noreferrer" target="_blank"&gt;Python mini format language&lt;/A&gt;​&amp;nbsp; applies to python 2.7 and 3.4 etc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Learn more....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-blog-small" data-containerid="1167" data-containertype="37" data-objectid="55177" data-objecttype="38" href="https://community.esri.com/blogs/dan_patterson/2015/10/13/before-i-forget-17-formatting-in-action" target="_blank"&gt;https://community.esri.com/blogs/dan_patterson/2015/10/13/before-i-forget-17-formatting-in-action&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:43:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/format-numbers-in-field-calc-python/m-p/307457#M23917</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T14:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Format numbers in Field Calc/Python</title>
      <link>https://community.esri.com/t5/python-questions/format-numbers-in-field-calc-python/m-p/307458#M23918</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not good with the .format string function, but the .zfill string function should do what you need&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from &lt;A href="https://docs.python.org/2/library/string.html" title="https://docs.python.org/2/library/string.html"&gt;7.1. string — Common string operations — Python 2.7.10 documentation&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/2/library/string.html" title="https://docs.python.org/2/library/string.html"&gt;https://docs.python.org/2/library/string.html&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;TT class="descclassname"&gt;string.&lt;/TT&gt;&lt;TT class="descname"&gt;zfill&lt;/TT&gt;&lt;BIG&gt;(&lt;/BIG&gt;&lt;EM&gt;s&lt;/EM&gt;, &lt;EM&gt;width&lt;/EM&gt;&lt;BIG&gt;)&lt;/BIG&gt;&lt;A class="headerlink" href="#string.zfill" title="Permalink to this definition"&gt;¶&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Pad a numeric string &lt;EM&gt;s&lt;/EM&gt; on the left with zero digits until the given &lt;EM&gt;width&lt;/EM&gt; is reached.&amp;nbsp; Strings starting with a sign are handled correctly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2015 16:21:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/format-numbers-in-field-calc-python/m-p/307458#M23918</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2015-10-13T16:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: Format numbers in Field Calc/Python</title>
      <link>https://community.esri.com/t5/python-questions/format-numbers-in-field-calc-python/m-p/307459#M23919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is specifically handled by &lt;A href="https://docs.python.org/2/library/string.html#string.zfill" rel="nofollow noopener noreferrer" target="_blank"&gt;zfill()&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; block = 5236
... print str(block).zfill(5)
...
05236&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:43:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/format-numbers-in-field-calc-python/m-p/307459#M23919</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T14:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Format numbers in Field Calc/Python</title>
      <link>https://community.esri.com/t5/python-questions/format-numbers-in-field-calc-python/m-p/307460#M23920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Awesome! Thanks for the quick responses everyone, I used the zfill function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2015 16:28:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/format-numbers-in-field-calc-python/m-p/307460#M23920</guid>
      <dc:creator>GeorgePapamihalakis</dc:creator>
      <dc:date>2015-10-13T16:28:09Z</dc:date>
    </item>
  </channel>
</rss>

