Mike Baas > Math-PercentChange-0.07 > Math::PercentChange

Download:
Math-PercentChange-0.07.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.07   Source  

NAME ^

Math::PercentChange - calculate the percent change between two values

VERSION ^

Version 0.07

SYNOPSIS ^

  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%
# or
  my $diff = f_percent_change($from, $to, "%.03f", 1); # 50.000

percent_change

Calculate the percent change between two values. Returns the percent difference.

f_percent_change

Calculate the percent change. Returns a dualvar. When used in numeric context, returns an unformatted 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 ("%.2f") and appends a percent sign.

Passing a fourth argument (1) will prevent the routine from appending a percent sign.

AUTHOR ^

Mike Baas <mbaas@cpan.org>

ACKNOWLEDGEMENTS ^

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.

LICENSE ^

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: