<?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: Custom script tool parameters will not accept decimals in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1110291#M62766</link>
    <description>&lt;P&gt;Interestingly, all I had to do was change &lt;STRONG&gt;&lt;EM&gt;arcpy.GetParameterAsText()&lt;/EM&gt;&lt;/STRONG&gt; to &lt;STRONG&gt;&lt;EM&gt;arcpy.GetParameter()&lt;/EM&gt;&lt;/STRONG&gt;. Then I didn't even have to bother with later changing the value to a float.&lt;/P&gt;</description>
    <pubDate>Fri, 22 Oct 2021 15:32:18 GMT</pubDate>
    <dc:creator>JaredPilbeam2</dc:creator>
    <dc:date>2021-10-22T15:32:18Z</dc:date>
    <item>
      <title>Custom script tool parameters will not accept decimals</title>
      <link>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1108558#M62670</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="b1.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25445i2067FA4BB77832EA/image-size/large?v=v2&amp;amp;px=999" role="button" title="b1.png" alt="b1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have a script tool that sets a layer's break values and their labels. The user will also need to enter decimals as values. I can't seem to get the tool to do that. Here I have the break values set to accept a Long data type. I've also tried a double, and a string.&lt;/P&gt;&lt;P&gt;The break values entered into the tool are forced to be integers in the script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#class break values
classbreakvalues = sys.argv[1] #break value parameter entered here
breakvalues_list = classbreakvalues.split(";")
new_breakvalues_list = []
for brkvalues in breakvalues_list:
    newbreak = int(brkvalues) # integer value
    new_breakvalues_list.append(newbreak)
classBreakValues = new_breakvalues_list&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I run the following, the tool won't accept a decimal value.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="b2.png" style="width: 541px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25453iBB2A98C84EB81798/image-size/large?v=v2&amp;amp;px=999" role="button" title="b2.png" alt="b2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I get this error, which I understand to mean you can't have an string as an integer. But I don't see how that could be.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markdown"&gt;ValueError: invalid literal for int() with base 10: '70.5'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 19:38:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1108558#M62670</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-10-18T19:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: Custom script tool parameters will not accept decimals</title>
      <link>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1108582#M62671</link>
      <description>&lt;LI-CODE lang="python"&gt;classbreakvalues.split(";")&lt;/LI-CODE&gt;&lt;P&gt;suggests that the values are being returned as a semicolon delimited string.&amp;nbsp; If that is the cast them to a float when you get them.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;vals = "40;45;70.5;100"

v = vals.split(";")

v0 = [float(i) for i in v]

v
['40', '45', '70.5', '100']

v0
[40.0, 45.0, 70.5, 100.0]&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 18 Oct 2021 20:43:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1108582#M62671</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-10-18T20:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: Custom script tool parameters will not accept decimals</title>
      <link>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1108583#M62672</link>
      <description>&lt;P&gt;The int type can't have decimals so you need to use a float conversion if you want to persist the decimal values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;newbreak = float(brkvalues) # integer value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can cast to float first then int, but it will truncate your number.&lt;/P&gt;&lt;P&gt;val = int(float(brkvalues))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 21:15:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1108583#M62672</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-10-18T21:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Custom script tool parameters will not accept decimals</title>
      <link>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1108830#M62685</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;newbreak = [float(i) for i in brkvalues]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;If I use that it gives me: &lt;EM&gt;TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;@Anonymous UserI used &lt;EM&gt;&lt;STRONG&gt;float(brkvalues&lt;/STRONG&gt;)&lt;/EM&gt; and set the tool Data Type to Double. The tool ran with no error, but the value I set to a decimal was not changed in the symbology. And yes, I've noticed &lt;EM&gt;&lt;STRONG&gt;newbreak = int(float(brkvalues))&lt;/STRONG&gt;&amp;nbsp;&lt;/EM&gt;doesn't show the decimal places in the symbology either.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Oct 2021 15:31:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1108830#M62685</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-10-20T15:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: Custom script tool parameters will not accept decimals</title>
      <link>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1108850#M62688</link>
      <description>&lt;P&gt;Using&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;newbreak =&lt;/STRONG&gt;&lt;/EM&gt; &lt;STRONG&gt;&lt;EM&gt;float(brkvalues) &lt;/EM&gt;&lt;/STRONG&gt;also does something with the highest value in a particular field. I set the last upper break value to be 100 in the tool parameters before I ran it. But, for some reason its grabbing the highest value in a particular layer's table and setting it as the last upper value in the symbology. Here, for example, 69.57 is the highest value in the % Vaccinated - 14-16 field. It ignores my label and it shows a decimal?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JaredPilbeam2_0-1634656325481.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25530iD4C7A797970A4CAD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JaredPilbeam2_0-1634656325481.png" alt="JaredPilbeam2_0-1634656325481.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 15:21:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1108850#M62688</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-10-19T15:21:52Z</dc:date>
    </item>
    <item>
      <title>Re: Custom script tool parameters will not accept decimals</title>
      <link>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1108967#M62693</link>
      <description>&lt;P&gt;you have to int a float not a string, hence int(float("1.1")), but int("1") is ok (refer to type conversion docs in python)&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 18:34:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1108967#M62693</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-10-19T18:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: Custom script tool parameters will not accept decimals</title>
      <link>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1109373#M62718</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JaredPilbeam2_0-1634754762147.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/25654iBAA3B225D804E9DF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JaredPilbeam2_0-1634754762147.png" alt="JaredPilbeam2_0-1634754762147.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All three of the following arrangements in the code are successful when running them from the script tool. But, not one of them change the break value to a decimal in the layer's symbology. This leads me to believe something is up with the tool.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Results in neither decimal in layer symbology nor print statement
for brkvalues in breakvalues_list:
    newbreak = int(float(brkvalues))
    arcpy.AddMessage(f'newbreak: {newbreak}')

#prints these values
#break value: 40
#break value: 45
#break value: 60
#break value: 100

#No decimal in layer symbology, but decimal in print statement
for brkvalues in breakvalues_list:
    newbreak = float(brkvalues)
    arcpy.AddMessage(f'break value: {newbreak}')

#prints these values
#break value: 40
#break value: 45
#break value: 60.9
#break value: 100

#No decimal in layer symbology, but decimal in print statement
from decimal import Decimal
for brkvalues in breakvalues_list:
    newbreak = Decimal(brkvalues)
    arcpy.AddMessage(f'break value: {newbreak}')

#prints these values
#break value: 40
#break value: 45
#break value: 60.9
#break value: 100&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Oct 2021 18:33:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1109373#M62718</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-10-20T18:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Custom script tool parameters will not accept decimals</title>
      <link>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1109466#M62721</link>
      <description>&lt;P&gt;OK, I was too focused on one part of the script. The snippet I had posted above was the section of code that takes the users input and puts it into a variable. Then there is the other part of the script the assigns that input to the upperBound element of the symbology. This is what I needed to convert to a float! Thanks for your answers.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, sys

aprx = arcpy.mp.ArcGISProject('CURRENT')

#make sure fields in list are in same order as maps in project
fields =  ['VaccPercentageTotPop', 'VaccPercentage11to14', 'VaccPercentage0to18', 'VaccPercentage12to18',  
           'VaccPercentage14to16', 'VaccPercentage16to18', 'VaccPercentage19to64', 'VaccPercentage65Plus']

c = 0 #use counter to give a number to each map in for loop
for map in aprx.listMaps():
    arcpy.AddMessage(f'--- map: {map.name} ---')
    layers = map.listLayers()
    for layer in layers:
        arcpy.AddMessage(f'layer: {layer.name}')
        sym = layer.symbology   
        #Reset renderer 
        sym.updateRenderer('SimpleRenderer')
        sym.updateRenderer('GraduatedColorsRenderer')

        if hasattr(sym, 'renderer') and layer.name.startswith('BaseLayer'):
            Renderer = sym.renderer
            Renderer.classificationField = fields[c]
            #class break values
            classbreakvalues = arcpy.GetParameterAsText(0)
            breakvalues_list = classbreakvalues.split(";")
            new_breakvalues_list = []
            for brkvalues in breakvalues_list:
                newbreak = brkvalues
                arcpy.AddMessage(f'break value: {newbreak}')
                new_breakvalues_list.append(newbreak)
            classBreakValues = new_breakvalues_list
            #class break labels
            classbreaklabels = arcpy.GetParameterAsText(1)
            breaklabels_list = classbreaklabels.split(";")
            classBreakLabels = breaklabels_list

            # Run the Renderer.breakCount function to use the classBreakValues 
            # array parameters as the values, and create a counter.
            Renderer.breakCount = len(classBreakValues)

            i = 0 
            for brk in Renderer.classBreaks:
                brk.upperBound = float(classBreakValues[i]) #&amp;lt;-- Convert this to float
                arcpy.AddMessage(f'upper bound in symbology: {brk.upperBound}')
                brk.label = classBreakLabels[i]
                i+=1

                layer.symbology = sym
    c+=1
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Oct 2021 21:33:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1109466#M62721</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-10-20T21:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Custom script tool parameters will not accept decimals</title>
      <link>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1110291#M62766</link>
      <description>&lt;P&gt;Interestingly, all I had to do was change &lt;STRONG&gt;&lt;EM&gt;arcpy.GetParameterAsText()&lt;/EM&gt;&lt;/STRONG&gt; to &lt;STRONG&gt;&lt;EM&gt;arcpy.GetParameter()&lt;/EM&gt;&lt;/STRONG&gt;. Then I didn't even have to bother with later changing the value to a float.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Oct 2021 15:32:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/custom-script-tool-parameters-will-not-accept/m-p/1110291#M62766</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2021-10-22T15:32:18Z</dc:date>
    </item>
  </channel>
</rss>

