--- loncom/homework/default_homework.lcpm 2002/05/31 22:19:06 1.47
+++ loncom/homework/default_homework.lcpm 2002/07/17 18:08:39 1.48
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
#
-# $Id: default_homework.lcpm,v 1.47 2002/05/31 22:19:06 albertel Exp $
+# $Id: default_homework.lcpm,v 1.48 2002/07/17 18:08:39 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -442,31 +442,61 @@ sub floor {return (($_[0]-int($_[0]))==
sub format {
my ($value,$fmt)=@_;
- return sprintf('%.'.$fmt,$value);
+ my $dollarmode;
+ if ($fmt =~ /^\$(.*)/) { $fmt=$1; $dollarmode=1; }
+ my $result=sprintf('%.'.$fmt,$value);
+ if ($dollarmode) {$result=&dollarmode($result);}
+ return $result;
}
sub prettyprint {
my ($value,$fmt)=@_;
my $result;
+ my $dollarmode;
+ if ($fmt =~ /^\$(.*)/) { $fmt=$1; $dollarmode=1; }
if ($fmt) { $value=sprintf('%.'.$fmt,$value); }
if ($value =~ /([0-9\.\-\+]+)E([0-9\-\+]+)/ ) {
my $frac=$1;
+ if ($dollarmode) { $frac=&dollarformat($frac); }
my $exponent=$2;
$exponent=~s/^\+0*//;
- if (!$exponent) { return $frac; }
- if ($external::target eq 'web') {
- $result=$frac.'×10'.$exponent.'';
- } elsif ($external::target eq 'tex') {
- $result='\ensuremath{'.$frac.'\times 10^{'.$exponent.'}}';
+ if ($exponent) {
+ if ($external::target eq 'web') {
+ $result=$frac.'×10'.$exponent.'';
+ } elsif ($external::target eq 'tex') {
+ $result='\ensuremath{'.$frac.'\times 10^{'.$exponent.'}}';
+ } else {
+ $result=$value;
+ }
} else {
- $result=$value;
+ $result=$frac;
}
} else {
$result=$value;
+ if ($dollarmode) { $result=&dollarformat($result); }
}
return $result;
}
+sub dollarformat {
+ my ($number) = @_;
+ if ($number =~ /\./) {
+ while ($number =~ /([^\.,]+)([^\.,][^\.,][^\.,])([,0-9]*\.[0-9]*$)/) {
+ $number = $1.','.$2.$3;
+ }
+ } else {
+ while ($number =~ /([^,]+)([^,][^,][^,])([,0-9]*)$/) {
+ $number = $1.','.$2.$3;
+ }
+ }
+ if ($external::target eq 'tex') {
+ $number='\$'.$number; #' stupid emacs
+ } else {
+ $number='$'.$number; #' stupid emacs
+ }
+ return $number;
+}
+
sub map {
my ($phrase,$dest,$source)=@_;
my @seed = &random_seed_from_phrase($phrase);