## WeBWorK Main Forum

### How force answer to be ONLY a decimal in PGML? or ONLY a fraction? (No operations allowed.) ### How force answer to be ONLY a decimal in PGML? or ONLY a fraction? (No operations allowed.)

by Christian Seberino -
Number of replies: 2
How force answer to be ONLY a decimal in PGML? or ONLY a fraction? (No operations allowed.)

Imagine an arithmetic test where you wanted student to avoid taking
advantage of Webwork's flexibility in allowing operations like

cs ### Re: How force answer to be ONLY a decimal in PGML? or ONLY a fraction? (No operations allowed.)

by Davide Cervone -
These features are controlled by the Context that you have selected. The answers in PGML use the currently active context, so if you set the context to the Fraction context, for example, then the answer will only be able to be fractions. E.g.,
    loadMacros("contextFraction.pl");
Context("Fraction-NoDecimals");
BEGIN_PGML
.5 = [_______]{"1/2"}
END_PGML

would force the student to enter a value that produces .5 without using decimal numbers (but perhaps one of the strict fraction contexts would be better, here, see the documentation for details).

Similarly, you could use the limited numeric context to force decimal representation:

    Context("LimitedNUmeric");
BEGIN_PGML
[:1/2:] = [_______]{.5}
END_PGML

would not accept 1/2.

You can do both in the same problem by doing:

    loadMacros("contextFraction.pl");
Context("Fraction-NoDecimals");
$ans1 = Compute("1/2"); Context("LimitedNumeric");$ans2 = Compute(".5");

BEGIN_PGML
[.5] = [_______]{$ans1} [:1/2:] = [_______]{$ans2}
END_PGML

Hope that helps.

Davide 