You're not reading the latest revision of this page, which is here.

Rounding

The following example shows a input.number question:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
\begin{question}
 
  \begin{variables}
    \randdouble{a}{1}{2}
  \end{variables}
 
  \type{input.number}
  \field{real}
  \displayprecision{6}
  \correctorprecision[rounded]{3}
 
  \text{Round \var{a} to three decimal places.}
 
  \begin{answer}
    \text{Answer: }
    \solution{a}
  \end{answer}
 
\end{question}
  • \correctorprecision determines the amount of digits behind the decimal mark the corrector will be using to determine if the user where answer was correct and
  • \displayprecision determines the amount of digits behind the decimal mark when displaying a number of type real.

The default value for both is set to 2.

There are three options for comparing the real answer and solution.

  • atleast (default) : means that the answer must be typed in (rounded) with atleast the given precision. We explain the precise meaning of atleast in the context of the above example.

The variable $$a_3$$
the the variable $$a$$ rounded to three decimal places. The answer is correct if $$abs(a_3 - studentAnswer) leq 0.0005 $$

1
2
The variable  $a_3$ denotes
the the variable $a$ rounded to three decimal places. The answer is correct if $\abs(a_3 - \text{student_answer}) leq 0.0005$
  • rounded : means that the answer must be rounded. If you use this option, make sure you tell the users that they must round the result with the given precision.
  • truncate : means that the answer should not be rounded, and should just be typed in up to the defined number of decimal digits.

displayprecision ≥ correctorprecision

Display precision has to be bigger or equal than corrector precision.

1
2
3
\displayprecision{4}
% Real numbers will be shown with 4 digits behind the decimal mark,
% but correct with only 2 (default).
1
2
3
\correctorprecision{4}
% The following is NOT allowed,
% since displayprecision (default 2) is now smaller than the correctorprecision

Rounding the calculated value of a function


When a function was created using the calculate option, the precision defined with the above command will be ignored.

This is because computations should not be rounded if they are not visible to the user. In case you do want to display calculated value then set the precision within the function command. Again this value should be ≥ than the corrector precision.

\function[calculate, <number>]{<var>}{<expression>} will calculate the <expression> and round the result according to the value of <number> . The option <number>, should only be used when you want to display the result of the calculated function on the screen. If <number> is not provided calculate will result in a number with an accuracy of up to 16 digits (default) behind the decimal mark.

Alternatively, if you want to display numbers calculated from a function rounded to smaller digits than the corrector precision, you can use the floor function to achieve that.

Example

Let's say corrector precision is 2, but you want the number a displayed truncated or rounded without any
decimal places. You can do the following: (two options)

1
2
3
\randdouble{a}{0}{10}
\function[calculate]{a1}{floor(a)}     % truncated
\function[calculate]{a2}{floor(a+0.5)} % rounded to integers