File Coverage

blib/lib/Float/Truncate.pm
Criterion Covered Total %
statement 15 15 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 24 26 92.3


line stmt bran cond sub pod time code
1             package Float::Truncate;
2              
3 1     1   72317 use strict;
  1         11  
  1         30  
4 1     1   27 use 5.008_005;
  1         4  
5             our $VERSION = '0.01';
6 1     1   5 use vars qw/@ISA @EXPORT @EXPORT_OK/;
  1         2  
  1         216  
7             require Exporter;
8             @ISA = qw(Exporter);
9             @EXPORT = @EXPORT_OK = qw/truncate truncate_force/;
10              
11             sub truncate {
12 2     2 0 98 my ( $number, $length ) = @_;
13 2 100       11 return $number unless $length;
14              
15 1         17 return sprintf "%.${length}f", $number;
16             }
17              
18             sub truncate_force {
19 2     2 0 9 my ( $number, $length ) = @_;
20 2 100       15 return $number unless $length;
21            
22 1         4 $length = 10 ** $length;
23 1         9 return int( $number * $length ) / $length;
24             }
25              
26             1;
27             __END__