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

Rounding

The following example shows a number input question with one single answer as a constant:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
\begin{question}
 
  \begin{variables}
    \function{f}{a/b}
    \number{a}{11}
    \number{b}{16}
  \end{variables}
 
  \type{input.number}
  \field{real}
  \displayprecision{3}
  \correctorprecision[rounded]{3}
 
  \text{Determine the decimal expansion of $\var{f}$ correct to three decimal places.}
  \explanation{Think about what rounded off to three decimal places means.}
 
  \begin{answer}
    \text{Answer: }
    \explanation{The explanation belong to this specific answer.}
    \solution{f}
  \end{answer}
 
\end{question}

In the above example the following new commands where used:

  • \text: an optional label that will be placed in front of an answer (input) field
  • \solution: the solution that will be used to compare with the answer of the user
  • \precision: determines
    • a.) the amount of digits behind the decimal mark the corrector will be using to determine if the user answer was correct and
    • b.) the amount of digits behind the decimal mark when displaying a number of type real.

The default value for precision is set to 2.

Both a.) and b.) can be overridden using \correctorprecision and \displayprecision respectively.

  • \correctorprecision: overrides the (default 2) value of \precision when comparing the correct solution with the user answer.
  • \displayprecision: overrides the (default 2) value of \precision when displaying real numbers on the screen.

Logically displayprecision ≥ correctorprecision

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
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.
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