<?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 Python script for converting strings to numbers in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-script-for-converting-strings-to-numbers/m-p/701715#M54366</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I need to convert two fields entered as strings into numbers so that I can do simple arithmetic on them using the field calculator. In ArcGIS 10 Desktop, within the field calculator, what script/function should I use?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All of the posts I have read on this problem suggest scripts that are no longer in the new version of ArcGIS 10.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 31 Jul 2011 22:02:51 GMT</pubDate>
    <dc:creator>EstherSullivan</dc:creator>
    <dc:date>2011-07-31T22:02:51Z</dc:date>
    <item>
      <title>Python script for converting strings to numbers</title>
      <link>https://community.esri.com/t5/python-questions/python-script-for-converting-strings-to-numbers/m-p/701715#M54366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I need to convert two fields entered as strings into numbers so that I can do simple arithmetic on them using the field calculator. In ArcGIS 10 Desktop, within the field calculator, what script/function should I use?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All of the posts I have read on this problem suggest scripts that are no longer in the new version of ArcGIS 10.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Jul 2011 22:02:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-for-converting-strings-to-numbers/m-p/701715#M54366</guid>
      <dc:creator>EstherSullivan</dc:creator>
      <dc:date>2011-07-31T22:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python script for converting strings to numbers</title>
      <link>https://community.esri.com/t5/python-questions/python-script-for-converting-strings-to-numbers/m-p/701716#M54367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you are asking what I think you are - the answer is that you can't... As far as I know, you cannot change the type of an existing field (i.e. turning a &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;string &lt;/STRONG&gt;&lt;SPAN&gt;field into a &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;long &lt;/STRONG&gt;&lt;SPAN&gt;field)... You have to create a new field, of the desired type (i.e. long) and use the field calculator to set the new field = to the old field, Arc will handle the conversion from string to number (or whatever); then you can delete the old field. Yes, I know this is a huge pain in the ass...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you actually meant: "how do I calculate numeric a value in Field Calculator if my inputs are text fields", then you need to do something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&lt;STRONG&gt;Pre-Logic Script Code:&lt;/STRONG&gt;
def myFunction(input1, input2):
&amp;nbsp; Input1 = int(input1)
&amp;nbsp; Input2 = int(input2)

&amp;nbsp; # do Calculation... i.e.
&amp;nbsp; # x = 2*Input1 + 3*Input2

&amp;nbsp; # return the result of the calculation - this value is placed in the new field...
&amp;nbsp; return x

&lt;STRONG&gt;Expression:&lt;/STRONG&gt;
myFunction(!input1!, !input2!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Use &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;int&lt;/STRONG&gt;&lt;SPAN&gt; if all the input numbers are integers (that is no decimal points), or &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;float&lt;/STRONG&gt;&lt;SPAN&gt; if any of the input numbers have decimals...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:30:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-for-converting-strings-to-numbers/m-p/701716#M54367</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-12T05:30:57Z</dc:date>
    </item>
  </channel>
</rss>

