Math::PercentChange - calculate the percent change between two values
Version 0.03
use Math::PercentChange qw(percent_change); my $from = 10; my $to = 5; my $diff = percent_change($from, $to); # -50 use Math::PercentChange qw(f_percent_change); my $from = 10; my $to = 15; my $diff = f_percent_change($from, $to, "%.03f); # 50.000%
Calculate the percent change between two values. Returns the percent difference.
Calculate the percent change. Returns a Scalar::Util. When used in numeric context, returns an unforatted percentage value. When used in string context, returns a formatted sprintf value.
Formatting options for sprintf can be passed as a third argument. If no formatting option is passed, the default rounds to two decimal places and a percent sign ("%.2f%").
Passing a fourth argument will disable the addition of a percent sign.
Mike Baas <mbaas@cpan.org>
This extremely simple code was taken from Mark Jason Dominus' correction of David Wheeler's blog post on the subject matter of 'How To Calculate Percentage Change Between Two Values'. See http://www.justatheory.com/learn/math/percent_change.html for the original posting.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Math::PercentChange, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::PercentChange
CPAN shell
perl -MCPAN -e shell install Math::PercentChange
For more information on module installation, please visit the detailed CPAN module installation guide.