Select to view content in your preferred language

Decimals NOT being truncated/rounded

2683
15
Jump to solution
10-25-2017 11:51 AM
deleted-user-LNABNwA5CZcD
New Contributor III

For points, I added some geometry fields (POINT_X and POINT_Y as automatically generated), which were created as Double type.

I want them to display as my label (e.g., "35.596821, -81.235600"). I went to the numeric formatting and changed to 6 as that's the number of decimal places I want.

For some (not all; most are fine), there is infinite repeat (e.g., "-81.39291999999999"). Here is my label code: Round($feature.POINT_Y, 6) + ", " + Round($feature.POINT_X, 6)

I've played around with the field calculator, even trying to create new fields and convert to different types, but that's not working.

HELP!!!

1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

Add a text field, use that as the convertor .  The format conversion will perform if point_x is indeed a number, it should fail with an error otherwise. 

If you can replicate my example in your python IDE using python 3.5, then there is something wrong with the labelling 

My example is Python... make sure that you specify python if there is any other options

View solution in original post

15 Replies
DanPatterson_Retired
MVP Emeritus

If you just need the field for labelling (that is another issue that can probably be solved directly)

I take it that is Arcade?

In python you can use the formatting characteristics builtin to convert a numeric value to string with complete control over the justification and number of decimals.  

"{:10.6f}".format(-81.39291999999999)
'-81.392920'

I am sure equivalent abilities exist in other labelling languages

deleted-user-LNABNwA5CZcD
New Contributor III

Tried this in Python for the label, and it didn't work. Not sure what I'm missing. Is that truly all (with POINT_X replacing 81.39291999999) that should be needed?

0 Kudos
DanPatterson_Retired
MVP Emeritus

Add a text field, use that as the convertor .  The format conversion will perform if point_x is indeed a number, it should fail with an error otherwise. 

If you can replicate my example in your python IDE using python 3.5, then there is something wrong with the labelling 

My example is Python... make sure that you specify python if there is any other options

deleted-user-LNABNwA5CZcD
New Contributor III

Ok, figured it out just now. It was kind of backwards. I was able to go off the original Double field (POINT_X). In Python, and the decimal places and preserved characters were in opposite positions from what I thought:
'{:6.10}'.format([POINT_X])

Still seems inefficient, and something is off with the Round() function I'd still be curious to figure out, but at least it works. Thank you!

JayantaPoddar
MVP Esteemed Contributor

Ensure you are working on a layer pointing to a Feature Class, not an Event Layer.

What happens if you write a similar expression for Labeling as follows (Python Parser):

round(float([POINT_X]), 6) + ", " + round(float([POINT_Y]), 6)



Think Location
0 Kudos
StayMappy
New Contributor III

I have this problem and none of these solutions are working. I need the calculated number to be rounded. When I have tried to use the above solutions I keep getting this. This is causing a problem because this is how is is being displayed as well. 

#arcpro#decimals

 

##

0 Kudos
DanPatterson_Retired
MVP Emeritus

it you calculate the values into a text field, as in my suggestion above, then you can control the output format easily

0 Kudos
StayMappy
New Contributor III

This is what happened when I tried your code

0 Kudos
DanPatterson_Retired
MVP Emeritus

is that a text field?

python parser in the field calculator

I just tried it 

a = 91.1234567890
"{:6.2f}".format(a)
' 91.12'
0 Kudos