version 1.165, 2014/06/24 17:02:33
|
version 1.167, 2014/06/25 10:48:39
|
Line 1045 sub format_significant_figures {
|
Line 1045 sub format_significant_figures {
|
my $numSig = $xint*10**($x10-$sig+$power); |
my $numSig = $xint*10**($x10-$sig+$power); |
if ($numSig =~ /^(\d+)\.(\d+)/) { |
if ($numSig =~ /^(\d+)\.(\d+)/) { |
# insert trailing zero's if have decimal point |
# insert trailing zero's if have decimal point |
|
my @digarray = split('',$1.$2); |
|
my $sigcount; |
|
while (@digarray > 0) { |
|
my $item = shift(@digarray); |
|
if ($item) { |
|
$sigcount = 1 + @digarray; |
|
last; |
|
} |
|
} |
|
if (($sigcount) && ($sig >= $sigcount)) { |
|
$zeros = substr($zeros,0,($sig - $sigcount)); |
|
} |
$numSig =~ s/^(\d+)\.(\d+)(\e?(.*)?)$/$1\.$2$zeros$3/; |
$numSig =~ s/^(\d+)\.(\d+)(\e?(.*)?)$/$1\.$2$zeros$3/; |
} else { |
} else { |
if ($numSig =~ /0$/) { |
if ($numSig =~ /^(\d+)e([\+\-]\d+)$/i) { |
|
my $pre_exp = $1; |
|
my $exponent = $2; |
|
$numSig = $pre_exp.'.'.$zeros.'E'.$exponent; |
|
} elsif ($numSig =~ /0$/) { |
# add decimal pt for number ending with 0 and length == # of sig figs |
# add decimal pt for number ending with 0 and length == # of sig figs |
if (length($numSig) == $sig) { |
if (length($numSig) == $sig) { |
$numSig.='.'; |
$numSig.='.'; |
Line 1055 sub format_significant_figures {
|
Line 1071 sub format_significant_figures {
|
# exponential form for number ending with 0 and length > # of sig figs |
# exponential form for number ending with 0 and length > # of sig figs |
my $fmtsig = $sig-1; |
my $fmtsig = $sig-1; |
if ($fmtsig) { |
if ($fmtsig) { |
$numSig = sprintf('%.'.$fmtsig.'e',$numSig); |
$numSig = sprintf('%.'.$fmtsig.'E',$numSig); |
} |
} |
|
} elsif (length($numSig) < $sig) { |
|
$numSig.='.'.substr($zeros,0,($sig-length($numSig))); |
|
} |
|
} else { |
|
if (length($numSig) < $sig) { |
|
$numSig.='.'.substr($zeros,0,($sig-length($numSig))); |
} |
} |
} |
|
if (length($numSig) < $sig) { |
|
$numSig.='.'.substr($zeros,0,($sig-length($numSig))); |
|
} |
} |
} |
} |
# return number with sign |
# return number with sign |