CFLib.org – Common Function Library Project

booleanize([value])

Last updated July 3, 2006

author

Craig M. Rosenblum

Version: 1 | Requires: CF7 | Library: DataManipulationLib

Description:
This was to help deal with a problem of access/sql conversion and there were some yes/no values that did not match to boolean values. So had to create a script to simplify universal conversion to boolean values.

Return Values:
Returns 1 or 0.

Example:

<cfset one = "true">
<cfset two = "0">
<cfset new_one = 0>
<cfset new_two = 0>

<b>default values:</b><br>
<cfoutput>
one = #one#<br>
two = #two#<br>
</cfoutput>
<cfoutput>
<b>New Values:</b><br>
one = #booleanize(one)#<br>
two = #booleanize(two)#<br>
</cfoutput>

Parameters:

Name Description Required
value The value to convert. No

Full UDF Source:

/**
 * Simply converts access yes/no or other boolean variables to 0/1 format, almost opposite of yesnoformat
 * 
 * @param value 	 The value to convert. (Optional)
 * @return Returns 1 or 0. 
 * @author Craig M. Rosenblum (crosenblum@gmail.com) 
 * @version 1, July 3, 2006 
 */
function booleanize(value) {
	if (not isboolean(value)) {
		value = replacenocase(value,'on',1);
		value = replacenocase(value,'off',0);
	}
	if (yesnoformat(value) eq 'Yes') value = 1;
	if (yesnoformat(value) eq 'No') value = 0;
	return value;
}
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