CFLib.org – Common Function Library Project

Factor(integer)

Last updated September 06, 2001

author

Rob Brooks-Bilson

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Returns a list of all factors for a given positive integer.

Return Values:
Returns a comma delimited list of values.

Example:

<CFSET n=100>
  <CFOUTPUT>
  Given n=100
  The factors of #n# are: {#Factor(n)#}
  </CFOUTPUT>

Parameters:

Name Description Required
integer Any non negitive integer greater than or equal to 1. Yes

Full UDF Source:

/**
 * Returns a list of all factors for a given positive integer.
 * 
 * @param integer      Any non negitive integer greater than or equal to 1. 
 * @return Returns a comma delimited list of values. 
 * @author Rob Brooks-Bilson (rbils@amkor.com) 
 * @version 1.1, September 6, 2001 
 */
function factor(integer)
{
  Var i=0; 
  Var Factors = "";
  for (i=1; i LTE integer/2; i=i+1) {
    if (Int(integer/i) EQ integer/i) {
      Factors = ListAppend(Factors, i);
    }
  }
  Return ListAppend(Factors, integer);
}

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