This UDF will work, within limits (only tests for least common denominators
under 11, but could be expanded):
<cffunction name="frac" access="public" returntype="string" output="No">
<cfargument name="decimalVal" type="numeric" required="Yes">
<cfscript>
var rtn = "0";
var dec = arguments.decimalVal;
var num = 0;
var den = 100;
var intList = "10,9,8,7,6,5,4,3,2";
var x = 0;
var test = 0;
var loopOK = false;
var loopAgain = true;
if (dec < 1 and dec > 0) {
// only process if we've got a fractional value to begin with
num = dec * den; // multiply numerator by denominator;
// loop to test for common demoninators
while (loopAgain ) {
loopOK = false;
for (x = 1; x lte listLen(intList); x++) {
test = listGetAt(intList, x);
if (not num mod test and not den mod test) {
num = num / test;
den = den / test;
loopOK = true;
}
}
if (not loopOK) {
loopAgain = false;
}
}
rtn = num & "/" & den;
}
return rtn;
</cfscript>
</cffunction>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:315873
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4