--- loncom/homework/caparesponse/caparesponse.pm 2002/09/30 18:32:45 1.61
+++ loncom/homework/caparesponse/caparesponse.pm 2002/10/01 20:17:42 1.63
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.61 2002/09/30 18:32:45 sakharuk Exp $
+# $Id: caparesponse.pm,v 1.63 2002/10/01 20:17:42 sakharuk Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -225,13 +225,23 @@ sub end_numericalresponse {
if ($target eq 'web') {
$result.= '
';
for ($ind=0;$ind<$number_of_bubbles;$ind++) {
+ my $ans;
if ($formats[0] ne '') {
- my $ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);
- $result.=''.$alphabet[$ind].': '.$ans.' | ';
+ $ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);
} else {
- my $ans = sprintf('%.'.'d',$bubbles_values[$ind]);
- $result.=''.$alphabet[$ind].': '.$ans.' | ';
+ my $badans = $bubbles_values[$ind];
+ my $format = '';
+ #What is the number? (integer,decimal,floating point)
+ if ($badans=~/^(\d*\.?\d*)(E|e)(\d*)$/) {
+ $format = 'e'.$2;
+ } elsif ($badans=~/^(\d*)\.(\d*)$/) {
+ $format = '4f';
+ } elsif ($badans=~/^(\d*)$/) {
+ $format = 'd';
+ }
+ $ans = sprintf('%.'.$format,$bubbles_values[$ind]);
}
+ $result.=''.$alphabet[$ind].': '.$ans.' | ';
}
$result.='
';
} elsif ($target eq 'tex') {
@@ -260,17 +270,27 @@ sub end_numericalresponse {
}
$result.='}\hline';
for ($ind=$cou;$ind<$cou+$table_range[$j];$ind++) {
+ my $ans;
if ($formats[0] ne '') {
- my $ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);
- $result.=' '.$alphabet[$ind].': & '.$ans.' ';
+ $ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);
} else {
- my $ans = sprintf('%.'.'d',$bubbles_values[$ind]);
- $result.=' '.$alphabet[$ind].': & '.$ans.' ';
+ my $badans = $bubbles_values[$ind];
+ my $format = '';
+ #What is the number? (integer,decimal,floating point)
+ if ($badans=~/^(\d*\.?\d*)(E|e)(\d*)$/) {
+ $format = 'e'.$2;
+ } elsif ($badans=~/^(\d*)\.(\d*)$/) {
+ $format = '4f';
+ } elsif ($badans=~/^(\d*)$/) {
+ $format = 'd';
+ }
+ $ans = sprintf('%.'.$format,$bubbles_values[$ind]);
}
+ $result.=' '.$alphabet[$ind].': & '.$ans.' ';
if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}
}
- $j++;
$cou += $table_range[$j];
+ $j++;
$result.='\\\\\hline\end{tabular}\vskip 0 mm ';
}
}