# Value: Rounding to decimal places

In order to round numbers and amounts to 0, 1 or 2 decimal places, you can use the round(var, x) functionality, where ‘var’ stands for any chosen variable name AND ‘x’ for the number of decimal places.

In order to round a value specified in an open question, you must set up the following elements:

• An open question (question code: q1) in which a value can be entered with or without decimals. Response data type: Real number & Text field size: Small.
• A value assignment with a user-defined variable name, e.g. round1. Under Data type, you can select the variable Real number. In the text box Is equal to the following term: you then specify the formula: round(q1, 0) or round(q1, 1) or round(q1, 2). The value specified in the open question is then rounded to 0, 1 or 2 decimal places, depending on the formula defined. Finally, in the Execute setting, you select the option Anytime (immediately after every change to an involved variable). This value assignment can be inserted BEFORE the open question.
• A text block (optional) in which you can use variables (to be selected from the RTE window) to present the entered and rounded value to the participant. In the text block above, you will see three rounding variables. Obviously, this is only possible provided you have included three value assignments before the open question in the survey.

When specifying a value in the open question of the survey, a participant will then be shown anything like the following:

The value 6.458 (here with a dot due to Anglo-Saxon number notation) provided by a participant is rounded to 0, 1 and 2 decimal places using the custom placeholders {{custom.round1}} to {{custom.round3}}.

Note: In the raw data, you will see the value entered by the participant and the rounded value calculated using the value assignment.

Calculating and rounding the average

Suppose a Mathematics test is administered to all pupils in four periods of a school year. For each period, the marks including 1 decimal place are recorded for each pupil. Using a value assignment, an average can be calculated and this average can in turn be rounded to a number of decimal places (e.g. 1) using another value assignment.

To set up this issue, you will need the following elements:

• Four open questions (question code: q1 to q4) in which a mark with or without decimal place can be entered for each period. These open questions can be included directly below each other in the survey. Response data type: Real number & Text field size: Small.
• A value assignment with a user-defined variable name, e.g. Average_mark. Under Data type, you can select the variable Real number. In the text box Is equal to following term: you then specify the formula: (q1+q2+q3+q4)/4. The marks entered in the open questions q1 to q4 with or without a decimal are added together and divided by 4. The average can be displayed with 3 decimal places, e.g. (7.1+7.3+5.1+4.4)/4= 5.975. Finally, in the Execute setting, you select the option Anytime (immediately after every change to an involved variable). This value assignment can be inserted AFTER the open questions.
• A value assignment with a user-defined variable name, e.g. round1. Under Data type, you can select the variable Real number. In the text box Is equal to the following term: you then specify the formula: round(Average_mark, 1). The average calculated using the Average_mark value assignment is then rounded to one decimal place. Finally, in the Execute setting, you select the option Anytime (immediately after every change to an involved variable). This value assignment can be inserted BEFORE the open questions.
• A text block (optional) in which you can use custom variables (to be selected from the RTE window) to present the average and rounded mark to the participant. In the text block above, you will see a variable for calculating the average and a variable for rounding it.

During the survey, marks can be entered in the open questions after which the average and rounded average will be calculated. This then looks for a participant more or less as depicted in the image below (provided a text block has been included in the survey):

The average 5.975 (here with a dot due to the Anglo-Saxon number format) calculated using the custom placeholder {{custom.Average_mark}} is rounded to one decimal place (6.0) using the custom placeholder {{custom.round1}}.

Note: In the raw data, you will not only see the marks entered in questions q1 to q4, but also the average and rounded mark calculated using a value assignment.

Updated on May 2, 2023