Format for decimal numbers

2275
2
08-03-2018 03:17 AM
JürgenBiendara1
New Contributor III

Hello,

I am using a "decimal" question type and want to restrict the answers to a certain range and to a specific format:

  • Only values between 0 and 14
  • Up to two leading digits (before decimal separator)
  • Up to two decimal places
  • Decimal separator optional when no decimal places
  • No leading zero

I have tried various options, but none was completely satisfying.

Constraint

With a constraint like ". >= 0 and . <= 14" it is not possible to restrict the number of decimal places.

Input Mask

The input mask enforces the answer to exactly match the mask, i. e. the value 1 for the input mask 99.99 would require the answer 01.00, otherwise the answer fails validation.

Regex

I cannot think of any regular expression that fulfills all above mentioned restrictions since it has to do two things: Set limits to the allowed values (0 <= x <= 14) and also format the answer correctly. Moreover, I have the impression that in Survey123 regular expressions don't work correctly when applied to a decimal question.

So, what I need is a combination of constraint and

  • either input mask -> which would need to be more flexible (e. g. not enforcing the answer to exactly match the mask)
  • or regular expression
  • or the possibility to delimiter the number of digits before and after the decimal separator.

Does anyone have an idea how to deal with this?

Are there any enhancements planned for a future version of Survey123?

Right now, is it possible to combine a value limiting constraint and a regular expression (I was not successful with my tests)?

Thank you very much, best regards,

Jürgen

0 Kudos
2 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Jürgen,

To test for a maximum of 2 decimal places, I would multiply the number by 100 and compare it against the integer of that number * 100:

. * 100 = int(. * 100)

This can be added on to your current constraint.

As for the requirement that there be no leading 0, why is that relevant in the entering of a number?  0.04 and .04 are equivalent numbers.

0 Kudos
JürgenBiendara1
New Contributor III

Hi James,

Thanks for the hint, again pretty simple.

As for the leading zero: The integer and decimal question types also allow e. g. 001 or 0003.12 respectively. This can be confusing and isn't, let's say, good style. But this is only cosmetic, not an error.

Best regards,

Jürgen

0 Kudos