I have a python toolbox (.pyt) where the user selects a layer, a field from that layer and then values from that field. The tool uses this to make a selection based on the field values. It's working fine for all other datatypes (integer, text/string, float) but there is an issue with double that I think I've narrowed down to precision.
Manually making the selection by attribute the field value is 0.1000000014901162 (works). The value displayed in the tool is 0.100000001490116 (see image).
The field is data type double with a precision of 0 and scale of 0 (see image).
I would like a solution that will work across any precision/scale. I've tried using python's decimal, but that gives too high a precision 0.100000001490116119384765. This one selection is part of a very long script but I've disassembled the functions and here are the relevant bits (not indented/functional):
#def getParameterInfor(self):
# FC
landUse = arcpy.Parameter("Landuse/Greenspace Polygons",
"land_use", "GpFeatureLayer", "Optional", "Input")
# Field
LULC_field = arcpy.Parameter("Greenspace Field", "LULCFld", "Field",
"Optional", "Input")
# List of fields from table
landVal = arcpy.Parameter("Greenspace Field Values", "grn_field_val",
"GPString", "Optional", "Input", multiValue=True)
LULC_field.parameterDependencies = [landUse.name]
landVal.parameterDependencies = [LULC_field.name]
landVal.filter.type = 'ValueList'
#def updateParameters(self, p):
# Conditions must be met for each input to become active
if True in [p[4].value, p[6].value]:
p[17].enabled = True
else:
p[17].enabled = False
if p[17].altered:
p[18].enabled = True
if p[18].altered:
in_poly = p[17].valueAsText
TypeField = p[18].valueAsText
p[19].enabled = True
p[19].filter.list = unique_values(in_poly, TypeField)
#def main()
landuse = params[17].valueAsText
field = params[18].valueAsText
fieldLst = params[19].values
# Convert the list of unicode to float
fieldLst = map(float, fieldLst)
# Make selection
arcpy.MakeFeatureLayer_management(landuse, "lyr")
# Create where clause from list
exp =''
for item in fieldLst:
if type(item) == float:
exp += '"{}" = {} OR '.format(field, float(item))
whereClause = exp[:-4]
sel = "NEW_SELECTION"
arcpy.SelectLayerByAttribute_management("lyr", sel, whereClause)
I haven't included all the code to differentiate datatypes, but the above currently works on float and other datatypes are differentiated either when converting from unicode or when creating a where clause from the list.