I ported the Perl module Math::SigFigs to PG to enable for significant figures to be checked in student responses. These routines return the expected results and numerically this appears to be a viable approach. One relatively minor issue is that the $correct and $student->value variables do not appear to be strings and thus do not retain the precision that is needed for direct use. If this issue cannot be resolved, I can recode a tolerance-type functionality in the custom answer checker.
A more significant issue is that the “Entered” and “Answer Preview” values displayed in the “Results for this submission” bar are also limited in their precision. To illustrate this, the attachment contains two screenshots. The top image displays the correct WeBWorK behavior where the student has properly calculated a numerical value but did not properly assess the correct number of sig figs. The below image represents a case where the student also provided the correct number of sig figs. In such circumstances, I could envision that some students may be confused by the limited precision shown in the regions circled in red with respect their answer (also circled).
If it is possible to rectify particularly the latter point in the problem space, I would appreciate direction. For reference, below is the portion of my code containing the question text and answer checker.
$num1="5.09738";
$num2="1000.10";
BEGIN_TEXT
Calculate the below sum and express your answer using the proper number of significant figures. $BR$BR
$num1 + $num2 = \{ ans_rule(15) \}. The answer is: \{ addSF($num1,$num2) \}$BR$BR
END_TEXT
$ans=Real(-1); #dummy variable to permit access to ANS()
ANS($ans-> cmp(
checker => sub {
my ($correct,$student,$ansHash) = @_;
my $sval = $ansHash->{original_student_ans};
$corr_string=addSF($num1,$num2);
if(Real($corr_string)==Real($sval)){
$nsf_val=CountSigFigs($sval); #num sig figs in $sval
$nsf_corr = CountSigFigs($corr_string); #num sig figs in corr_string
if($nsf_val==$nsf_corr){ return 1;}
else{
$ansHash->{ans_message}="Incorrect number of significant figures.";
return 0.5;
}
}
}#end sub{}
) #end cmp()
); #end ANS()