Hi,
It looks perhaps simple, but I am looking for the proper syntax in Python in order to print integer field correctly when running a script.
For the time being, I get:
ID:1.0000080689e+11
with:
gp.AddMessage("ID:" + str(input_text))
And I would prefer the proper integer value... What would be the syntax to format it correctly?
Thanks
Solved! Go to Solution.
I highly recommend getting familiar with Python string formatting. Try this:
id = 1.0000080689e+11 # gives you the same result gp.AddMessage("ID: {}".format(id)) # will display as a number with no decimals gp.AddMessage("ID: {:.0f}".format(id)) # or show off and add commas gp.AddMessage("ID: {:,.0f}".format(id))
Unless you have a really good reason to use gp (for example, you want to write code that is backwards-compatible to 9.3), I highly recommend using arcpy instead.
I highly recommend getting familiar with Python string formatting. Try this:
id = 1.0000080689e+11 # gives you the same result gp.AddMessage("ID: {}".format(id)) # will display as a number with no decimals gp.AddMessage("ID: {:.0f}".format(id)) # or show off and add commas gp.AddMessage("ID: {:,.0f}".format(id))
Unless you have a really good reason to use gp (for example, you want to write code that is backwards-compatible to 9.3), I highly recommend using arcpy instead.
Thanks. It works very well. As long as variable id is a number (integer or float) and not a string.
Also, I used the former 9.3 syntax because this script was initially made at that time and I haven't upgraded the code to arcpy...