booleanize([value])
Last updated July 03, 2006
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;
}
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