listAvg

Calculates average from all numeric values given in the list

listAvg(list [, delimiters] [, multiCharacterDelimiter]) → returns numeric

Member Function Syntax

list.listAvg([delimiters] [, multiCharacterDelimiter])

This function requires Lucee.  Not supported on Adobe ColdFusion, etc.

Argument Reference

list string
Required

delimiters string
Default: ,

multiCharacterDelimiter boolean
Default: false

Examples
Sample code invoking the listAvg function

athletes = queryNew('id,name,bestTime', 'integer,varchar,decimal');
queryAddRow(athletes,[{
	id: 0,
	name: 'Anne',
	bestTime: 15.4
},{
	id: 1,
	name: 'John',
	bestTime: 12.8
},{
	id: 2,
	name: 'Sue',
	bestTime: 9.1
}]);
writeOutput('Athlete''s average best time is #NumberFormat(listAvg(ValueList(athletes.bestTime)),'0.00')# seconds.');

Expected Result: Athlete's average best time is 12.43 seconds.

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub