CFLib.org – Common Function Library Project

forceBoolean(bool)

Last updated September 5, 2010

author

Alan McCollough

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
You pass in a variable, and I will return either a "1" if it evaluates to true, or a "0" if it is not a boolean (as in an empty string or any other non-boolean) or evaluates to false.

Return Values:
Returns a boolean.

Example:

<cfset i="">
<cfif i></cfif> returns error.
<ciff forceBoolean(i)></cfif> works.
#forceBoolean(i)# returns "0".

Parameters:

Name Description Required
bool Value to check. Yes

Full UDF Source:

/**
 * Returns a boolean 1/0 from anything, including empty strings.
 * 
 * @param bool 	 Value to check. (Required)
 * @return Returns a boolean. 
 * @author Alan McCollough (amccollough@anthc.org) 
 * @version 1, September 5, 2010 
 */
function forceBoolean(bool){
  if(isBoolean(bool) AND bool IS TRUE)
     return "1";
  else
     return "0";
}
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