WeBWorK Problems

Error in Currency

Error in Currency

by Robin Cruz -
Number of replies: 3
We upgraded to 2.7 this summer and I'm seeing an error that did not occur prior to the upgrade--it worked last year with ww_version: 2.5.1.3 | pg_version: 2.5.1.  

In the problem, the first answer must be entered in dollars.  When the answer, $1000 for instance, is entered, it is scored correct, but the answer is changed in the answer box to &#x24:1000 and apparently stored this way in the answer hash.  It you resubmit the problem, it scores the "new" answer left in the answer box as incorrect.  The problem's code is at the end of this note.

Thanks--rac
---------------NOTE: The graphing part was deleted to keep it short------------
DOCUMENT();        # This should be the first executable line in the problem.

loadMacros(
  "PGstandard.pl",
  "PGchoicemacros.pl",
  "MathObjects.pl",
  "PGgraphmacros.pl",
  "contextCurrency.pl",
  "answerHints.pl"
);

TEXT(beginproblem);

######################################
#  Setup

#--------Define the function-----------

$x = random(5,20,5);
$y = random(3000,6000,1000);
$C = random(1000,2000,1000);
$k = ln($y/$C)/$x;

$f = Formula("$C exp($k*x)");

$interval = "<0,25>";                     

#------------Define the graph-----------------------
# NOTE: deleted the graph to make this more compact
#-----------------------Year-----
$year = random(1950,1990,5);

######################################
#  Main text 

BEGIN_TEXT
$BCENTER
GRAPH
$ECENTER
$BR
A deposit is made into an interest-bearing account. The figure above shows the balance, \(B\), in the account \(t\) years later.
$PAR
(a) What was the original deposit?
$BR
Answer: \{ans_rule(10)\}
$PAR
(b) If deposit was made in $year,when does the balance reach $DOLLAR $y?
$BR
Answer: \{ans_rule(10)\}
END_TEXT

######################################
#  Answers

Context()->strings->add("No solution"=>{},
                        "Not defined"=>{},
                        "Does not exist"=> {},
                        "All real numbers"=>{});
Context("Currency");
$ans_a = $f->eval(x=>0)->with(tolerance=>0.15, tolType=>'absolute');
ANS(Currency($ans_a)->cmp);

Context("Numeric");
$ans_b = Compute("$year+$x");
ANS($ans_b->cmp->withPostFilter(AnswerHints( 
  Compute("$x") => "Did you enter the year?"
)));

######################################

ENDDOCUMENT(); # This should be the last executable line in the problem.
 
In reply to Robin Cruz

Re: Error in Currency

by Paul Pearson -
Hi Robin,

To ensure that the bug fixers actually see this, I submitted a bug report:

http://bugs.webwork.maa.org/show_bug.cgi?id=2703

Take care,

Paul Pearson
In reply to Robin Cruz

Re: Error in Currency

by Davide Cervone -
I looked into it this morning, and a little history is needed to understand it fully. The WeBWorK code for creating the answer blanks removes several potentially troublesome characters from the student answer before displaying it. These include the dollar sign in order to avoid the potential side-effect of having student answers cause perl variable substitution if used in certain contexts.

To get around this, the Currency object converts the dollar to the HTML entity &#x24;, which represents the dollar sign by giving its numeric Unicode position. These characters are not removed by WW, so they pass through unchanged, but the browser then converts the entity back to the dollar sign for display.

In April, the code that sets up the input fields was changed to convert HTML special characters to entities so that in case answers include them, they don't interfere with the HTML that is used to create the input field. This means, the &#x24; gets all its characters converted to a form so that the browser will preserve them. That means you don't see a dollar sign, but rather the &#x24; directly.

I don't see a way to fix that from within contextCurrency.pl directly, as there is no way around these two transformations.

My recommendation is to remove line 340 from pg/macros/PGbasicmacros.pl (which does the tr command to remove the special characters) and then restart the server (this is required). Finally, edit contextCurrency.pl to remove the loadMacro("problemPreserveAnswers.pl") call.

Davide