D
dan
Whilst trying to create something that would parse a number into one with
an appropriate number of significant figures, I accidentally wrote this:
sub sigfig {
my ($sigfigs, $number) = @_;
my $divisor = 10**(length(int $number) - $sigfigs);
$number /= $divisor;
$number = sprintf "%1.0f", $number;
$number *= $divisor;
return $number
}
which seems to work for positive numbers not in scientific notation.
As my friends and colleagues consider me big-headed, I would appreciate
it if somebody could point out any inadequacies,foibles and associated
notwithstandings of the above code, bringing me down a much needed peg or
to.
dan
an appropriate number of significant figures, I accidentally wrote this:
sub sigfig {
my ($sigfigs, $number) = @_;
my $divisor = 10**(length(int $number) - $sigfigs);
$number /= $divisor;
$number = sprintf "%1.0f", $number;
$number *= $divisor;
return $number
}
which seems to work for positive numbers not in scientific notation.
As my friends and colleagues consider me big-headed, I would appreciate
it if somebody could point out any inadequacies,foibles and associated
notwithstandings of the above code, bringing me down a much needed peg or
to.
dan