Decimal places

Mehr
1 Jahr 2 Wochen her #176024 von DB1324
Decimal places wurde erstellt von DB1324
Hi Everyone,


I have a survey which has several numeric input fields along the lines of 'How much did X cost?', but I can't for the life of me figure out how/where to validate the field to restrict to two decimal places (e.g. allow 12.55, but not 12.5, or 12.5555555)

I've been looking at RegEx I can't get it to work; I've tried putting it in 'Validation' ('/[0-9]+(\.[0-9][0-9]?)?/'), and in 'Question validation equation' (regexMatch('/[0-9]+(\.[0-9][0-9]?)?/')), but no joy.

We're running version 2.65.1+170522

Any help much appreciated - and apologies in advance if this is a stupid question.

Thanks

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

LimeSurvey Partners
Mehr
1 Jahr 2 Wochen her #176027 von tpartner
tpartner antwortete auf Decimal places
Try this as the question validation equation:

regexMatch("/^\d+(\.\d{1,2})?$/", self)

It will allow either an integer or enforce precision to two decimal places.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
1 Jahr 2 Wochen her #176029 von DB1324
DB1324 antwortete auf Decimal places
Perfect, thank you so much.

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
1 Jahr 2 Wochen her #176032 von DenisChenu
DenisChenu antwortete auf Decimal places
If you need to disable 12.5 , and allow only 12.50 : you need a text question type (since 12.50 === 12.5 in numeric).

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
An error happen ? Before make a new topic : remind the Debug mode .
Folgende Benutzer bedankten sich: tpartner

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
9 Monate 11 Stunden her #180629 von DB1324
DB1324 antwortete auf Decimal places
Hello,

Sorry to resurrect an old request, but I have since identified an issue with the solution that was kindly offered up here.

regexMatch("/^\d+(\.\d{1,2})?$/", self) will indeed limit responses to integers or values with two decimal places, but if I apply it to a non-mandatory question, the field effectively becomes mandatory because null/no answer gets picked up by the validation.

Is there a way of amending this validation to allow for no response?

Thank you!

(We are still running version 2.65.1)

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
9 Monate 10 Stunden her #180632 von tpartner
tpartner antwortete auf Decimal places
Try this (untested):

regexMatch("/^\d+(\.\d{1,2})?$|^$/", self)

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Folgende Benutzer bedankten sich: DB1324

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Mehr
9 Monate 10 Stunden her #180633 von DB1324
DB1324 antwortete auf Decimal places
Tony, that's brilliant - thank you so much!

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha