integer/decimal formatting?

822
3
11-14-2019 05:53 AM
BRYANHERRON
New Contributor III

Is there any way to format an integer question so that regardless of the number of characters typed in, the result. is a two-place decimal with the decimal point replaced with a + sign?

Here's what I need:

     input  =  result

            1 = 0+01  (+01 or +1 would be acceptable)

          12 = 0+12   (+12 would be acceptable)

        123 = 1+23

      1234 = 12+34

    12345 = 123+45

  123456 = 1234+56

1234567 = 12345+67

The mask function dictates the length of the string so is it possible to set  a calculation in the relevance column that checks the string length, thus controlling the result to be the desired result??

0 Kudos
3 Replies
Jim-Moore
Esri Regular Contributor

Hi BRYAN HERRON

Just to double-check, the user will input the digits in an integer question, is that right? The format you're after would need to be stored in a text question to accommodate the plus sign. One way to achieve this could be to use a combination of the string-length() and substr() functions, as described here: Formulas—Survey123 for ArcGIS | Documentation 

A calculation for the text question could look something like the below (given an input in an integer question called "int1"), but you would need to test this to make sure it works for your application. The calculation below should work for three-digit numbers and greater; you could then incorporate it into a nested if() statement to cover the one- and two-digit cases.

concat(substr(${int1},0,string-length(${int1})-2),'+',substr(${int1},string-length(${int1})-2,string-length(${int1})))

Hope this helps,

Cheers,

Jim

BRYANHERRON
New Contributor III

Thanks Jim, I knew there was a way to get there.

On a side note, I'm actually trying to figure out how to style the prompt and the answer on the same line. So one line instead of four. This space saving is something I'm trying to incorporate into all my questions.

0 Kudos
Jim-Moore
Esri Regular Contributor

Hi Bryan

You could save at least one line by showing the result in a note; store the calculation in a calculate question (which is hidden), then show the result in a note using a label like:

Stationing: ${calc1}

You could instead put the result in the hint for the integer question.

Alternatively, with the theme-grid appearance you can display questions side-by-side in cells. For more info, see this blog https://community.esri.com/groups/survey123/blog/2019/11/20/survey123-tricks-of-the-trade-groups-gri... and our documentation Appearance—Survey123 for ArcGIS | Documentation. There's also an XLSForm sample in Connect named Grid Style Groups.

Hope this helps,

Jim

0 Kudos