WeBWorK Main Forum

Decimal approximations not being accepted in Fraction context

Re: Decimal approximations not being accepted in Fraction context

by Danny Glin -
Number of replies: 0

If all you're looking for is the correct answer to be displayed as a fraction, then you can simply pass a string to Compute rather than a real number (which is the way Compute is supposed to be used):

Context("Numeric");
$ans = Compute("3/8");

BEGIN_PGML
[`3/8 = `] [__]{$ans}
END_PGML
Note that this won't reduce fractions.  In that case you will have to do something with Fraction objects.