CFLib.org – Common Function Library Project

PercentageChange(var1, var2)

Last updated July 3, 2002

author

Guillermo Cruz

Version: 1 | Requires: CF5 | Library: MathLib

Description:
This function can be used with any 2 numbers you want the percentage change on. Imagine two numbers that pertain to someone's weight. The first number is what they use to weigh and the second is what they currently weigh. You want to know the percentage difference with the + or minus attached to the outcome.

Return Values:
Returns a string.

Example:

<cfoutput>
PercentageChange(210,175) = #PercentageChange(210,175)#
</cfoutput>

Parameters:

Name Description Required
var1 The first number. Yes
var2 The second number. Yes

Full UDF Source:

/**
 * Check the percentage change between 2 numbers.
 * 
 * @param var1 	 The first number. (Required)
 * @param var2 	 The second number. (Required)
 * @return Returns a string. 
 * @author Guillermo Cruz (gcruz@elkiwa.com) 
 * @version 1, July 3, 2002 
 */
function PercentageChange(var1,var2){			
	var maxNumber = max(var1,var2);
	var minNumber = min(var1,var2);
	var change = maxNumber - minNumber;
	var symbol = "";
		
	if (var1 EQ var2)   return 0;
	change = NumberFormat(change / var1 * 100, 0.00);	
	
	if(var1 GT var2) symbol = "-";
	else symbol = "+";

	return symbol & " " & change;	
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson