File Coverage

lib/Spreadsheet/Engine/Function/FV.pm
Criterion Covered Total %
statement 15 15 100.0
branch 2 4 50.0
condition 1 2 50.0
subroutine 5 5 100.0
pod 2 2 100.0
total 25 28 89.2


line stmt bran cond sub pod time code
1             package Spreadsheet::Engine::Function::FV;
2              
3 28     28   142 use strict;
  28         65  
  28         888  
4 28     28   140 use warnings;
  28         54  
  28         742  
5              
6 28     28   143 use base 'Spreadsheet::Engine::Fn::investment';
  28         54  
  28         7233  
7              
8 25     25 1 571 sub result_type { Spreadsheet::Engine::Value->new(type => 'n$') }
9              
10             sub calculate {
11 25     25 1 1024 my ($self, $r, $n, $pmt, $pv, $type) = @_;
12 25   50     76 $pv ||= 0;
13 25 50       58 $type = $type ? 1 : 0;
14              
15 25 50       73 return -$pv - ($pmt * $n) if $r == 0; # simple calculation if no interest
16             return -(
17 25         782 $pv * (1 + $r)**$n + $pmt * (1 + $r * $type) * ((1 + $r)**$n - 1) / $r);
18             }
19              
20             1;
21              
22             __END__