# How to write labels with varying significant figures/decimal places?

I have results that range from ex. 113,009 down to 0.00495 - Can someone recommend a way to write/construct a label expression for the following in ArcMap:

• If less than 1, use 2 decimal places (or three if absolutely necessary to show the first non-zero value) • From 1 to 10, use 1 decimal place • If 10 or greater, use no decimal places

Or a way to quickly generate a new text column/field which adheres to the above?

-
Great - thanks guys! – Michael Mar 27 '14 at 18:17
If my answer to your question worked, could you accept it as the correct answer? Thanks. – ianbroad Mar 27 '14 at 18:22
Certainly, sorry about that...done. – Michael Mar 27 '14 at 18:25

Put the code below as the label expression for your feature in ArcMap. Set the parser to Python and check the Advanced box. Change [yourField] to the field containing the values you want to label.

``````def FindLabel([yourField]):
if [yourField] is not None:
value = float([yourField])
if value < 1:
return round(value, 3)
elif 1 <= value < 10:
return round(value, 1)
else:
return round(value, 0)
else:
return None
``````

I put the values that are less than one to three decimal places, but change it to two if you want.

-
Please do not "correct" the elif line here because the `elif 1 <= value < 10:`syntax is quite valid and, I think, more pythonic than a non-author edit which was made to it and approved. – PolyGeo Mar 27 '14 at 8:11
@PolyGeo yes my bad and I apologize. I saw it and the quick reaction from the programmer in me changed it so that it made sense to someone reading it. Both work. For the record `pythonic` at times is synonymous with esoteric which generally is not good for reusable code. – JamesSLC Mar 27 '14 at 18:00
@JamesSLC Yeah, well, you know, that's just, like, your opinion, man. – ianbroad Mar 27 '14 at 18:19
@ian I agree. No worries/disrespect though, I upvoted your answer. – JamesSLC Mar 27 '14 at 18:22
@JamesSLC No I didn't think that. I just wanted to use a quote from The Big Lebowski :) – ianbroad Mar 27 '14 at 18:23