--- loncom/homework/caparesponse/caparesponse.pm 2000/10/13 14:32:42 1.9 +++ loncom/homework/caparesponse/caparesponse.pm 2000/10/13 14:59:31 1.10 @@ -38,10 +38,23 @@ sub end_caparesponse { $args=$$parstack[$#$parstack]; } my $answer = &Apache::run::run("{$args;".'return $answer}',$safeeval); - if ( $answer eq $response ) { - return "Correct, Computer had $answer

"; - } else { - return "Incorrect, Computer had $answer

"; + if ( $answer == 1.0 * $answer ) { + my $tol = &Apache::run::run("{$args;".'return $tol}',$safeeval); + my $format = &Apache::run::run("{$args;".'return $format}',$safeeval); + my $formatedanswer = sprintf('%.'.$format,$answer); + my $difference = abs($answer - $formatedanswer); + my $studiff = abs($answer - $response); + if ( $difference > $studiff ) { + return "Correct, Computer had $answer

"; + } else { + return "Incorrect, Computer had $answer

"; + } + } else { + if ( $answer eq $response ) { + return "Correct, Computer had $answer

"; + } else { + return "Incorrect, Computer had $answer

"; + } } } else { #return "The correct answer is ".&Apache::run::run("{$$parstack['-1'];".'return $answer}',$safeeval)."\n";