--- loncom/homework/default_homework.lcpm 2005/03/31 14:43:13 1.97 +++ loncom/homework/default_homework.lcpm 2005/04/01 13:58:25 1.99 @@ -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.97 2005/03/31 14:43:13 albertel Exp $ +# $Id: default_homework.lcpm,v 1.99 2005/04/01 13:58:25 ng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -518,11 +518,12 @@ sub format { #if ($options =~ /\$/) { $dollamode=1; } #if ($options =~ /,/) { $commamode=1; } if ($options =~ /\./) { $alwaysperiod=1; } + my $result; if ($fmt=~/s$/i) { $result=&format_significant_figures($value,$fmt); } else { $fmt=~s/e/E/g; - my $result=sprintf('%.'.$fmt,$value); + $result=sprintf('%.'.$fmt,$value); if ($alwaysperiod && $fmt eq '0f') { $result .='.'; } $result=~s/(E[+-]*)0/$1/; } @@ -680,6 +681,11 @@ sub format_significant_figures { my $numSig = $xint*10**($x10-$sig+$power); # insert trailing zero's if have decimal point $numSig =~ s/^(\d+)\.(\d+)(\e?(.*)?)$/$1\.$2$zeros$3/; + # put a decimal pt for number ending with 0 and length = # of sig fig + $numSig.='.' if (length($numSig) == $sig && $numSig =~ /0$/); + if (length($numSig) < $sig) { + $numSig.='.'.substr($zeros,0,($sig-length($numSig))); + } # return number with sign return $sign.$numSig;