tempConvert(otemp, ctype)
Last updated April 25, 2006
Version: 1 | Requires: CF6 | Library: ScienceLib
Description:
This is an almost all inclusive function to convert temperatures between common formats. I haven't included the Rankine and Reaumure scales with this edition but they will be coming soon.
The function uses two-character strings to perform the required action. For example:
CF converts Celsius to Fahrenheit
FC converts Fahrenheit to Celsius
KC converts Kelvin to Celsius
CK converts Celsius to Kelvin
FK converts Fahrenheit to Kelvin
KF converts Kelvin to Fahrenheit
so the funtcion call would look like so:
tempconvert('30','CF')
this will convert 30 degrees Celsius to the equivalent temperature Fahrenheit.
Return Values:
Returns a string.
Example:
<cfset convertType = 'CF'>
<cfset convertThis = '30'>
<cfoutput>#tempconvert(convertThis,convertType)#</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
otemp | Temperature. | Yes |
ctype | Two character string that determines the conversion. | Yes |
Full UDF Source:
<!---
Converts temperatures from and to Celsius, Fahrenheit and Kelvin.
@param otemp Temperature. (Required)
@param ctype Two character string that determines the conversion. (Required)
@return Returns a string.
@author Jack Poe (jackpoe@yahoo.com)
@version 1, April 9, 2007
--->
<cffunction name="tempConvert" output="false" returnType="string">
<cfargument name="otemp" required="yes" type="numeric">
<cfargument name="ctype" required="yes" type="string">
<cfif arguments.ctype IS 'CF'>
<cfset convertedtTemp = (arguments.otemp*1.8)+32>
<cfset convertedtTemp = convertedtTemp & 'º F'>
<cfreturn convertedtTemp>
<cfelseif arguments.ctype IS 'FC'>
<cfset convertedtTemp = (arguments.otemp-32)*0.5555>
<cfset convertedtTemp = convertedtTemp & 'º C'>
<cfreturn convertedtTemp>
<cfelseif arguments.ctype IS 'CK'>
<cfset convertedtTemp = arguments.otemp+273.15>
<cfset convertedtTemp = convertedtTemp & 'º K'>
<cfreturn convertedtTemp>
<cfelseif arguments.ctype IS 'KC'>
<cfset convertedtTemp = arguments.otemp-273.15>
<cfset convertedtTemp = convertedtTemp & 'º C'>
<cfreturn convertedtTemp>
<cfelseif arguments.ctype IS 'FK'>
<cfset convertedtTemp = ((arguments.otemp-32)*0.5555)+273.15>
<cfset convertedtTemp = convertedtTemp & 'º K'>
<cfreturn convertedtTemp>
<cfelseif arguments.ctype IS 'KF'>
<cfset convertedtTemp = ((arguments.otemp-273.15)*1.8)+32>
<cfset convertedtTemp = convertedtTemp & 'º K'>
<cfreturn convertedtTemp>
</cfif>
</cffunction>
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