<?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: Covert double to float in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/covert-double-to-float/m-p/1226151#M65955</link>
    <description>&lt;P&gt;I use the same SearchCursor to inscept the double Field which has only 6 decimal point values return. Even i provided the spatial reference, the float Field value's decimal point is still inconsistent with the double Field&lt;/P&gt;&lt;P&gt;my search cursor is define as the following&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def get_field_values(cls, feat_cls_fp: str, field_name:str) -&amp;gt; list:
        table = arcpy.da.SearchCursor(
            in_table = feat_cls_fp, 
            field_names = field_name, 
            spatial_reference = arcpy.Describe(feat_cls_fp).spatialReference
            )
        return [row[0] for row in table]&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 27 Oct 2022 14:14:23 GMT</pubDate>
    <dc:creator>ChungLam</dc:creator>
    <dc:date>2022-10-27T14:14:23Z</dc:date>
    <item>
      <title>Covert double to float</title>
      <link>https://community.esri.com/t5/python-questions/covert-double-to-float/m-p/1226016#M65949</link>
      <description>&lt;P&gt;I got a field A which is double, but it only has 6 decimal points. I want to turn the field type to float&lt;/P&gt;&lt;P&gt;so i did the following&lt;/P&gt;&lt;P&gt;using arcpy.management.AddField to create a field B with&amp;nbsp;float type&lt;/P&gt;&lt;P&gt;use arcpy.management.CalculateField to copy the value from field A to field B&lt;/P&gt;&lt;P&gt;but the problem is after this conversion, I use&amp;nbsp;&lt;SPAN&gt;arcpy&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;SearchCursor to retrieve the value of field A and B and check if they are the same, it turns out&amp;nbsp;&lt;/SPAN&gt;field B value's&amp;nbsp;decimal point is more than field A&lt;/P&gt;&lt;P&gt;fieldA :&amp;nbsp;[0.046486, -0.466769, 0.562891, 0.783896, -0.837999, -1.58879, 2.39555, 1.38319, 1.93933, 1.48517, 1.73189, 0.723564, 0.414805, -0.014135, ...]&lt;/P&gt;&lt;P&gt;fieldB:&amp;nbsp;[0.04648600146174431, -0.4667690098285675, 0.5628910064697266, 0.7838960289955139, -0.8379989862442017, -1.5887900590896606, 2.395550012588501, 1.3831900358200073, 1.939329981803894, 1.4851700067520142, 1.7318899631500244, 0.7235640287399292, 0.41480499505996704, -0.014135000295937061, ...]&lt;/P&gt;&lt;P&gt;but this only happens if I inspect the field B value in python, in ArcGISPro, they are the same in the table&lt;/P&gt;&lt;P&gt;how may I make should that they will be the same even in Python? Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 02:24:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/covert-double-to-float/m-p/1226016#M65949</guid>
      <dc:creator>ChungLam</dc:creator>
      <dc:date>2022-10-27T02:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Covert double to float</title>
      <link>https://community.esri.com/t5/python-questions/covert-double-to-float/m-p/1226058#M65950</link>
      <description>&lt;P&gt;This sounds like you have to increase the nummber of displayed decimals for the field.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/data/tables/format-numeric-and-date-fields.htm" target="_blank"&gt;Format numeric and date fields—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 06:30:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/covert-double-to-float/m-p/1226058#M65950</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-10-27T06:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Covert double to float</title>
      <link>https://community.esri.com/t5/python-questions/covert-double-to-float/m-p/1226061#M65951</link>
      <description>&lt;P&gt;arcpy.SearchCursor is deprecated use&lt;/P&gt;&lt;P&gt;arcpy.da.SearchCursor&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/searchcursor-class.htm" target="_blank"&gt;SearchCursor—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;And did you specify a spatial reference when using it? you might be getting single precision returns if you didn't.&amp;nbsp; It is worth a check if indeed your inputs only have 6 decimal places to begin with&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 07:05:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/covert-double-to-float/m-p/1226061#M65951</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-10-27T07:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: Covert double to float</title>
      <link>https://community.esri.com/t5/python-questions/covert-double-to-float/m-p/1226151#M65955</link>
      <description>&lt;P&gt;I use the same SearchCursor to inscept the double Field which has only 6 decimal point values return. Even i provided the spatial reference, the float Field value's decimal point is still inconsistent with the double Field&lt;/P&gt;&lt;P&gt;my search cursor is define as the following&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def get_field_values(cls, feat_cls_fp: str, field_name:str) -&amp;gt; list:
        table = arcpy.da.SearchCursor(
            in_table = feat_cls_fp, 
            field_names = field_name, 
            spatial_reference = arcpy.Describe(feat_cls_fp).spatialReference
            )
        return [row[0] for row in table]&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 27 Oct 2022 14:14:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/covert-double-to-float/m-p/1226151#M65955</guid>
      <dc:creator>ChungLam</dc:creator>
      <dc:date>2022-10-27T14:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Covert double to float</title>
      <link>https://community.esri.com/t5/python-questions/covert-double-to-float/m-p/1226178#M65958</link>
      <description>&lt;P&gt;The display in the ArcGISPro table does not show the extra decimal point. In fact, they are the desired values. They are the same as the original double field, it is what I expect to see when I inspect the float field with &lt;SPAN&gt;arcpy.da.SearchCursor.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I tried the following ways in calculating the value in the float field&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1. using arcpy.da.UpdateCursor&lt;/SPAN&gt;&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;with arcpy.da.UpdateCursor(in_table = feat_cls_fp, field_names = [field_name, new_field_name]) as cursor:
    for row in cursor:
        row[1] = row[0]
        cursor.updateRow(row)&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;2. Using&amp;nbsp;&lt;SPAN&gt;arcpy.management.CalculateField&lt;/SPAN&gt;&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;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(
             in_table = feat_cls_fp,
             field = new_field_name,
             field_type = new_field_type,
             expression=f"!{field_name}!",
             expression_type="PYTHON3",
             enforce_domains="NO_ENFORCE_DOMAINS"
         )&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;In the above code, The new_field_name is the float field name, the field_name is the double field name.&lt;/P&gt;&lt;P&gt;and I check their consistency by the following custom function, which is basically using arcpy.da.SearchCursor&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;def get_field_values(cls, feat_cls_fp: str, field_name:str) -&amp;gt; list:
        table = arcpy.da.SearchCursor(
            in_table = feat_cls_fp, 
            field_names = field_name, 
            spatial_reference = arcpy.Describe(feat_cls_fp).spatialReference
            )
        return [row[0] for row in table]

field_values = get_field_values(feat_cls_fp, field_name)
new_field_values = get_field_values(feat_cls_fp, new_field_name)
assert field_values == new_field_values, f'Field {field_name} values changed after changing data type.'&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;but none of them produces the desired output and passes the assertion check.&lt;/P&gt;&lt;P&gt;the field_values are the same with the op fieldA value, which is the original double values&lt;/P&gt;&lt;P&gt;the new_field_values are the same with the op fieldB value, which is the converted float value, which has the extra decimal point after update/calculation.&lt;/P&gt;&lt;P&gt;I have also tried to create a new field with&amp;nbsp;&lt;SPAN&gt;arcpy&lt;/SPAN&gt;&lt;SPAN&gt;.management.AddField&lt;/SPAN&gt;, specifying the field type as 'FLOAT' and the field_precision and field_scale as 6. but it does not suppress the extra decimal point either.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 15:08:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/covert-double-to-float/m-p/1226178#M65958</guid>
      <dc:creator>ChungLam</dc:creator>
      <dc:date>2022-10-27T15:08:30Z</dc:date>
    </item>
  </channel>
</rss>

