File Coverage

blib/lib/Math/ScientificNotation/Util.pm
Criterion Covered Total %
statement 10 11 90.9
branch 6 8 75.0
condition 1 2 50.0
subroutine 2 2 100.0
pod 1 1 100.0
total 20 24 83.3


line stmt bran cond sub pod time code
1             package Math::ScientificNotation::Util;
2              
3             our $DATE = '2016-06-17'; # DATE
4             our $VERSION = '0.002'; # VERSION
5              
6 1     1   363 use Exporter qw(import);
  1         1  
  1         180  
7             our @EXPORT_OK = qw(sci2dec);
8              
9             sub sci2dec {
10 18     18 1 30 my $num = shift;
11 18 50       34 die "Please specify a number" unless defined $num;
12              
13 18 100       74 if ($num =~ /\A(?:[+-]?)(?:\d+\.|\d*\.(\d+))[eE]([+-]?\d+)\z/) {
    50          
14 16   50     53 my $num_digs_after_dec = length($1 || "") - $2;
15 16 100       28 $num_digs_after_dec = 0 if $num_digs_after_dec < 0;
16 16         136 return sprintf("%.${num_digs_after_dec}f", $num);
17             } elsif ($num =~ /\A[+-]?(?:\d+\.?|\d*\.\d+)\z/) {
18             # already in decimal notation
19 2         8 return $num;
20             } else {
21 0           die "Not a decimal number: $num";
22             }
23             }
24              
25             1;
26             # ABSTRACT: Utilities related to scientific notation
27              
28             __END__