Arcade expression round decimal to zero decimal places

26164
12
Jump to solution
01-10-2019 01:33 PM
AndrewL
Frequent Contributor

I have the following Arcade expression. However, it does not round to the nearest whole number. It always produces a number with two decimal places. Not sure if I am doing something wrong? Thanks.

var grid = $feature.GRIDCODE*10
var roundedValue = Round(grid, 0)
roundedValue

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

It's not the input attribute that requires formatting but the expression (sorry for the Spanish screenshot, but you get the idea):

View solution in original post

12 Replies
XanderBakker
Esri Esteemed Contributor

I guess all your values show two decimal zeros in the pop-up, right? If this is a value that is shown in the attribute table, remember that with the configure attributes of the pop-up you define the number of decimals to be used. Since the Round function returns a value, you still have to provide the correct format (0 decimals) in the attribute configuration in the pop-up. 

AndrewL
Frequent Contributor

Yes that's correct values show two decimal zeros in the pop-up. 

In the configure attributes I do have zero decimal places selected:

In the actual db the GRIDCODE field is a double.

XanderBakker
Esri Esteemed Contributor

It's not the input attribute that requires formatting but the expression (sorry for the Spanish screenshot, but you get the idea):

AndrewL
Frequent Contributor

Oh I see it now. Thanks! Yes that worked. 

XanderBakker
Esri Esteemed Contributor

Glad it works!

0 Kudos
WillAnderson
Occasional Contributor

Xander,

Is there a way to use Arcade to limit which number values show trailing zeros? For example, I want to use a number attribute for labelling. Some numbers have decimals values (e.g. 110.5), but must are whole numbers. Is there an Arcade expression I can use so we only see decimal values for values with decimals NOT zero (e.g. see values as 1, 2, 3, not 1.0, 2.0, 3.0)? I also want to avoid seeing zeros after decimals in popups.

0 Kudos
DataOfficer
Frequent Contributor

Hi @XanderBakker , I am doing something similar but using the expression in a custom attribute display, and therefore do not have the option to round the result afterwards. 

 

The expression is as follows:

 

// call the sites feature layer
var sites = FeatureSetById($map, /* Sites */ "Test_site_layer_8539")

// establish spatial relationship between the two layers and return a count
var grids = Count(Intersects($feature, sites))

// round the result

var roundgrids = Round(grids, 0)
return roundgrids

 

The test shows the number formatted correctly, but in the popups it still shows 2 decimal places. This is how the popup is formatted:

 

DataOfficer_0-1635268324633.png

 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @DataOfficer , 

The same applies. In the list of fields you will need to specify the decimals for the (virtual) field "expression/expr2". 

DataOfficer
Frequent Contributor

Ah got it, thanks.

0 Kudos