From: dpvc v. a. <we...@ma...> - 2005-07-04 15:47:10
|
Log Message: ----------- Implement "remove trailing zeros" format, like in prfmt(). I still think '%g' works better in most cases ('%f#' will print larger values without using scientific notation, which is nice, but will print small numbers like .000000005 as 0, even though the fuzzy comparison of this to zero will not be true.) Modified Files: -------------- pg/lib/Value: Real.pm Revision Data ------------- Index: Real.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Real.pm,v retrieving revision 1.15 retrieving revision 1.16 diff -Llib/Value/Real.pm -Llib/Value/Real.pm -u -r1.15 -r1.16 --- lib/Value/Real.pm +++ lib/Value/Real.pm @@ -202,7 +202,10 @@ my $self = shift; my $equation = shift; my $prec = shift; my $n = $self->{data}[0]; my $format = ($equation->{context} || $$Value::context)->{format}{number}; - $n = sprintf($format,$n) if $format; # use the specified precision, if any + if ($format) { + $n = sprintf($format,$n); + if ($format =~ m/#\s*$/) {$n =~ s/(\.\d*?)0*#$/$1/; $n =~ s/\.$//} + } $n = uc($n); # force e notation to E $n = 0 if $self == 0; # make near zero print as zero $n = "(".$n.")" if ($n < 0 || $n =~ m/E/i) && defined($prec) && $prec >= 1; |