I want to limit (constraint) the number of digits that are possible to enter after the point in decimal questions.
Unfortunately I couldn’t find what I want in the Community or Help Center.
I would like to limit to 0 or 1 digit after the point e.g.: 5 or 5.1
I’ve tried with regular expressions but wasn’t successful:
e.g.: regex(.,’^(.{0,1})$’)
Also I understood I could use a Text question type and put Numbers as Appearance but I want to be able to sum the values I obtained, so I guess it’s better to use Decimal questions.
round… with -decimalvalue (round(${{ }, -1) does not reflect decimal values (see 14.55 >> 10)
Question:
How can we best force a fixed number-conversion of numbers (e.g. for currency), WITH trailing 0?. Like user enters 14.1 >> system will transform to 14.10. Or user enters 14 >> system will transform to 14.00.
Kind regards
Many thanks @Kal_Lam and @wroos for your prompt answers.
I know it’s the more scientific and better way to do it.
However, what I really wanted was to constraint when entering the answer and give an error message if a value with more than one decimal digit would be entered.
That way I would avoid the intermediary calculation. Even though I must admit it’s not really a lot of extra work.
But at the same time I would make sure the person entering the value is really mentally present answering the question.
I think I finally found something working as I want it , at least with the value I tried to enter on Enketo it works.
So, with a Decimal question, as a Validation Criteria/Constraint, I used .<500 and regex(.,’^(\d{0,3})(\.[0-9]{0,1})?$')
In that way, the maximum acceptable value is smaller than 500. It includes that there can be a maximum of 3 digits before the point, which is not really necessary as the maximum is 500, but it didn’t work if I took it away (I’m not familiar enough with regex yet). And it accepts either no or only 1 decimal digit.
dot (.) is considered a special char in a regex expression. And since you are trying to use it here to represent an actual decimal point, you probably need to escape it; ie
Thanks @Xiphware for making me notice this.
I actually did include the “\” but it wasn’t shown in my message as I didn’t use the “Preformatted text” style.
Hello,
it;s fine, together with your . < 500. regex(.,’^([0-4]{0,1}[0-9]{0,2})(\.[0-9]{0,1})?$')
would cover the same alone.
Trailing zeros will be cut off by Enketo (before the constraint even), you can try with 499,900 or .00 (>> 0)
Best regards
as @wroos points out it’s probably due to a mistake in your syntax.
To obtain a rounded final result you have to do the division before the rounding.
In your example it would be round(${Salaire_Net} div 95 * 100, 0)
Hope it solves your problem
En français ça donne:
Si vous voulez que le résultat final soit arrondi il faut d’abord faire la division puis l’arrondir.
En effet, selon votre syntaxe, comme la division n’est pas inclue dans la parenthèse, elle a lieu après. C’est selon les règles de priorités des calculs mathématiques.
Si vous voulez un résultat final arrondi il vous faut l’inclure dans la partie à arrondir, c’est à dire dans la parenthèse, avant le nombre de décimal à inclure.
Votre exemple serait donc: round(${Salaire_Net} div 95 * 100, 0)
En espérant que cela solutionne votre problème.
Meilleures salutations
again, if you want to return an integer (which is a guess as it’s not explained in the question), then you need to include your division in the parenthesis of the int function.
by the way: as I learned myself in a previous post it would be better to write your operation/expression in “Preformatted text” style (see picture) so we don’t loose any part of it.