Hi there,

I am trying to solve a problem related to an old post

https://webwork.maa.org/moodle/mod/forum/discuss.php?d=2538

i'm trying to write an answer checker that will compare the correct and student entered values **and** their strings to yield a correct answer.

So given a correct value of 123.46, student entered values of 123.456 will be incorrect but also would be 123.46000 and 123.460. So the student value has to match the correct value **and** their strings should be identical. The rationale for the interested may be found here

According to https://webwork.maa.org/wiki/Custom_Answer_Checkers

The answer hash $anwserHash holds both the correct values and the strings of those values, respectively $ansHash{'correct_ans'} and $ansHash{'original_student_ans'}

With my limited perl and meagre knowledge of the inner workings of WeBWorK and after looking round, I've tried the following to no avail. It does not even grade the correct answer as correct. Also, If I chomp the strings 123.460 is graded as correct which is not the behaviour i'm looking for. Any help will be greatly appreciated.

$val = 123.45678

$ans = sprintf("%.2f", $val); # = 123.46

ANS( Real($ans)->cmp( checker=>sub {

( $correct, $student, $ansHash ) = @_;

$student_str = $ansHash{'original_student_ans'}; #unparsed student entry string

$correct_str = $ansHash{'correct_ans'}; #correct value string

return ((($correct == $student) && ($correct_str == $student_str))? 1 : 0)

}

) );