Hi Community.
I have an odd sort of first question. I am creating a path segment map, where the person requesting the map, would like the "Day", Description", "km" shown in the legend for various walking routes - this is easy to do if you have the correct fields in the attribute table - just add the multiple fields in a unique classification. For the distance field (KM), I have created a "Double" field for the distance in kilometers (in the JPEG below - this is field "KM". I have set the decimal places for this field to 1 digit - normal way with the Fields View setting - which rounds down the KM value from about 15 digits to 1. Ok, looks fine in the table.
But when you add the KM to my Legend - it expands the Double field decimal places out to 15 decimal places again - which really looks clunky. I would like the Double field to be "forced" to retain 1 decimal place only - so looking like the "Dist_Label" field (which I did in Excel). But I cant seem to be able to do this. So have tried various workarounds with different fields and edits.
If anyone has a suggestion how to do get my legend description to only have 1 decimal for a double field it would be great. Maybe I am missing something in the Legend formatting???
This leads me to my second question - my workaround in this case is to create a new text field, and convert the Double field to a Text string, and then concatenate that with any text I want - like adding the " km." text after the number. I can do this fairly easily with the python script: str(!KM!) + " km. But again, ArcPro expands out the decimal places (Field in the JPEG is Dist_lab). a Double value of 9.6 expands out to 9.610273752527856 km in my text converted field.
Does anyone let me know a rounddown python script to add to my convert to string calculation? I am not a coder so battle a bit with this. I have tried all sorts of examples like:
round.str(!KM!),1 - sort of stuff - dont laugh.
My only other way is to export the table to Excel - do all the conversions there and copy and past back to Arc. But this is very clunky.
Seems like a reasonable map request. Any advice appreciated.
Solved! Go to Solution.
they are two separate forms of the same thing... try putting just the first line in
the second line is an alternate form of the first
For your second question and assuming there are no nulls the simplest is to use string formatting either in its full form (line 1) or "f" string version (line 2). Python processing of course.
"{:.1f} km".format(!KM!)
f"{!KM!:.1f} km"
Readings
string — Common string operations — Python 3.14.0 documentation
some examples
Basic fancy formats .... - Esri Community
Thanks for the fast reply.
This will sound dim - but anyway. If I put that code in the space above the code block I get a syntax error.
If I put the code in the Code Block I get a "Fix a missing Parameter" response. Let me go through your Readings.
they are two separate forms of the same thing... try putting just the first line in
the second line is an alternate form of the first
Absolute legend - thank you - the top line worked in the Expression Box. 🙂 This solution will go into my GIS recipe book. Brilliant.