CFLib.org – Common Function Library Project

ListSum(listStr[, delim])

Last updated September 10, 2001

author

Douglas Williams

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Adds all the numbers in a delimited list returning the sum of the list.

Return Values:
Returns a numeric value.

Example:

<cfset mylist = "5,5,5">

<cfoutput>
The sum of my list is #listSum(mylist)#
</cfoutput>

Parameters:

Name Description Required
listStr Delimited list of numeric values you want to sum. Yes
delim Optional delimiter for the list. The default is the comma. No

Full UDF Source:

/**
 * Adds all the numbers in a delimited list returning the sum of the list.
 * 
 * @param listStr      Delimited list of numeric values you want to sum. 
 * @param delim      Optional delimiter for the list.  The default is the comma. 
 * @return Returns a numeric value. 
 * @author Douglas Williams (klenzade@i-55.com) 
 * @version 1.0, September 10, 2001 
 */
function listSum(listStr)
{
  var delim = ",";
  if(ArrayLen(Arguments) GTE 2) 
    delim = Arguments[2];
  return ArraySum(ListToArray(listStr, delim));
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson