version 1.166, 2014/06/24 18:02:47
|
version 1.167, 2014/06/25 10:48:39
|
Line 1059 sub format_significant_figures {
|
Line 1059 sub format_significant_figures {
|
} |
} |
$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 1067 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 |