Survey123 - Calculate to 2dp

4181
8
Jump to solution
08-30-2017 08:58 PM
JohnPlunkett
Esri Contributor

Hi there

I have a sample survey where I have a complex calcualtion, however I am interested in getting all answers with  2 decimal places only

I see that we can  edit the schema length, but with the way field length works we wont always consistently get 2dp

Thanks in advance

John P

1 Solution

Accepted Solutions
Philip-Wilson
Esri Notable Contributor

Hi John,

Have you considered using the 'round' function on your calculation:

round(${test}*1.14569875,2)

This will round the answer displayed to 2 decimal places and also submit the answer to feature service as only 2 decimal places.

Regards,

Phil.

View solution in original post

8 Replies
Philip-Wilson
Esri Notable Contributor

Hi John,

Have you considered using the 'round' function on your calculation:

round(${test}*1.14569875,2)

This will round the answer displayed to 2 decimal places and also submit the answer to feature service as only 2 decimal places.

Regards,

Phil.

MarcCavallaro
New Contributor III

Phil,  I see how this works for decimals but how can whole numbers be rounded? I need to round to the nearest 100. 

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Marc,

There are a couple of ways to round to the hundreds (and by extension, any order of magnitude):

  • round(${q}, -2) will round to the nearest hundreds (last two integer digits 0) - note this will round up if the value is greater than 50
  • ${q} - (${q} mod 100) will subtract the modulus (remainder) from dividing by 100 from the number, rounding it down to an even hundred
MarcusKlatt1
New Contributor II

Do these work when setting up the feature report word doc template? I am trying to round some lat/long values but don't want to go through the effort of creating a new field with a calculation in the Survey123 app.

Would a format like this work?: ${round(q,-2)}

I am wondering if this works for more than just the conditional element calcs as shown here: https://doc.arcgis.com/en/survey123/browser/analyze-results/featurereporttemplates.htm

${if integer1>0}

0 Kudos
Philip-Wilson
Esri Notable Contributor

Hi Marcus,

No, this is not supported in the feature report templates. The best way is to set up a hidden question on survey that does the rounding and final calculation, and then display that in the your feature report, not the originally entered value.

Phil.

0 Kudos
PrachiPatel
New Contributor III

Hey Phil, is there a way to round up? For example if the result of calculation is 71.415, is there a way to get the value to be 72? I have a calculation for estimating no. of employees where I'd rather have a conservative estimate instead of nearest round number.

0 Kudos
Philip-Wilson
Esri Notable Contributor

Hi @PrachiPatel,

Are you refering in the XLSForm in Connect/field app, or in the feature report template?

In either case there is no out of box supported function such as roundup that you may see supported in Excel, as the XSLForm open standard does not support it.

You could try and build your own expression to achieve what you are after, similar to what James outlined above. It will all depend on the values and types of number you need to round up to.

Regards,

Phil.

PrachiPatel
New Contributor III

Hi Phil

I am calculating in the .xls form. Thank you for your response. I went ahead and put the following calculation and it is working

if( (coalesce(${AREA},0) div 200) > round((coalesce(${AREA},0) div 200),0), round((coalesce(${AREA},0) div 200),0) +1 , round((coalesce(${AREA},0) div 200),0))