I have an attribute field that is API well numbers and when I calculate a "TEXT" field using arcpy it converts those API numbers into scientific notation. However, when I calculate the field in Arcmap using the GUI it stores the full API number correctly. Has anyone else had this issue? How might i ensure that this doesn't happen?
I have tried both:
arcpy.CalculateField_management(shapefile,fieldname,"!{}!".format(inputfieldname),"PYTHON")
and:
arcpy.CalculateField_management(shapefile,fieldname,"str(!{}!)".format(inputfieldname),"PYTHON")
Can you give an example number?
For instance, "30015364700000" will store as "3.00153647e+13".
The field width is > 14 characters and defined as Text for the output field?
The only other thing I can think of is explicitly formatting the output string
a = 30015364700000
"{:<14.0f}".format(a)
The field width is 255 and is a string. The code you provided only works if i change the 'f' to 's'.
I just tried using your code with both a feature class and shape file, and it works correctly for me, i.e, it doesn't use scientific notation. What version of ArcMap are you using?
Arc Version is 10.6.0.8321
If 'Long' in ArcMap or ArcGIS Pro is 32bit integers, then the maximum length of a field and the maximum value is dictated by the integer type. From other c based number types, these are as follows
32bit integers 10 characters with the maximum as 2,147,483,647
Arc* stores long as -2,147,483,648 to 2,147,483,647
64bit integers 19 characters with the maximum as 9,223,372,036,854,775,807
your number is 14 characters long as an integer, 30,015,364,700,000 .... beyond the 32bit long maximum
So if your key has to be that long, then you had better use a text field since
np.iinfo(np.int32).max
2147483647
np.iinfo(np.int64).max
9223372036854775807
Now if we convert that integer you have to float32 (32 bit float) we get
np.asarray([30015364700000]).astype(np.float32)
array([3.0015364e+13], dtype=float32)
I had to store the number as double and then use the code to covert to string. As you point out, the number can't be stored in long.
The field i am calculating from is a Double.