Select to view content in your preferred language

Rounding records pulled from related table?

437
1
07-25-2022 11:21 AM
DaveK
by
Frequent Contributor

Hello, 

I'm using the FeatureSetByRelationshipName to pull related table records into a popup. One of the fields (SumOfReturnMG) being pulled is an integer field and I need to round the number to 2 decimals. What would be be best way to format the field within my existing Arcade expression? 

Expression user below

var fs = FeatureSetByRelationshipName($feature,"qry_HUC_USEGROUP_RET" , ['*'], false);
var result = "";
var cnt = Count(fs);
if (cnt > 0) {
// start loop through related records
for (var f in fs) {
// for each f (=feature) in related features, add attendee to the result
result += TextFormatting.NewLine + f.YearNumber + TextFormatting.NewLine + f.SumOfReturnMG;
}
} else {
// overwrite result with text to indicate that there are no attendees
result = "";
}

return result;

Resulting record (field highlighted in blue)

DaveK_0-1658773174239.png

Thanks.

 

0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

You can use the Round() function.

Other stuff:

  • it's better to just load the fields you need to use less bandwidth, especially for large datasets
  • if you fill an array and concatenate it, you won't have the empty first line
  • if you restructure a bit, you can get rid of the nested code blocks
var fs = FeatureSetByRelationshipName($feature,"qry_HUC_USEGROUP_RET" , ["YearNumber", "SumOfReturnMG"], false);
var result = []; //array
// start loop through related records
for (var f in fs) {
// for each f (=feature) in related features, add attendee to the result
    Push(result, f.YearNumber + TextFormatting.NewLine + Round(f.SumOfReturnMG, 2);
}
// if result is empty, return a default value, else return the concatenated array
return IIF(Count(result) == 0, "", Concatenate(result, TextFormatting.NewLine))

Have a great day!
Johannes
0 Kudos