i have field named (depth) in feature class (point) with this spec :

float - 5 digits >>> 0.7186 or 0.9695

i create new field named (depth_new) with field calculator : round([depth],1) the result will be >>> 0.7186 = 0.7 or 0.9695 = 1

then i want to use (depth_new) field as label in my point feature class using arcpy, here is some of my statement in my code :

      lyr.labelClasses[0].expression = '"{}" & (left([depth_new],1)) & " " & "<SUB>" & (right( [depth_new],1)) & "</SUB>" & "{}"'.format("<FNT size = '17'><CLR blue = '255'>","</CLR></FNT>")

it is works fine, but as you can see on my code, i use "right" and "left" for the digit of the number that i want to show as label,

the problem is lets take a look at record with value = 0.7 it will be come 0.7 , but with value = 1 , the label will be 1.1 (so the number is changed, the correct should be 1.0)

i know i can solve this in field properties and check "pad with zeroes" and use 2 digit in properties, but let say i have 100 layers, so should i really do that for every 100 layers? i use arcpy for labelling to skip repitition and save time,

so any workaround or alternative way for this?


It is a formatting issue. Indeed, you could compute the rounding while formatting the value.

Using this doc, we see that we can specify (or not) a total output length, a padding for the units and a padding for the decimals.

Since you want only to pad 1 decimal with 0, the formatting code would be

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.