Question T6827
Visible to All Users

Limit decimal digits in computed question of type number

created 4 years ago (modified 4 years ago)

Hello,
I have a questionnaire with 3 questions of type number: question1, question2 and question3.
On the questionnaire I setup a trigger which sets question3=question2/question1 once question1 and question2 are not empty.
I'd like to display the value of question3 with maximum 2 decimal digits. Is it possible?

Answers approved by surveyjs Support

created 4 years ago

Hello,

You need to use the displayStyle and maximumFractionDigits options for the expression:

JavaScript
{ "pages": [ { "name": "page1", "elements": [ { "type": "text", "name": "question1", "inputType": "number" }, { "type": "text", "name": "question2", "inputType": "number" }, { "type": "expression", "name": "question3", "expression": "iif({question1}, {question2}/{question1}, 0)", "displayStyle": "decimal", "maximumFractionDigits": 2 } ] } ] }

Thanks, Serge
SurveyJS Team