Thanks for all of your input.
I figured out a way to get more consistent results. What I did was to add 0.0 to the
number in hopes that it would force internal conversion to float or double. Once I
did this I started getting consistent results. If any of you are interested here is
the UDF that I was working on to round to a specified number of significant digits:
(Please tell me what you think before I try to post it to cflib or something like
that.)
<cfscript>
//Name: RSigFig
//By: Jason Snyder
//Purpose: Round to specified number of significant digits.
//Parameters:
// 1. fInput - Number to process.
// 2. iDigits - The number of significant digits to return.
//Return: Number rounded to specified # of signficant digits.
function RSigFig(fInput, iDigits) {
//Local Variables
var iLog = 0;
var iTemp = 0;
var fReturn = 0;
//Execution
if (fInput NEQ 0) { //If not zero round to significant digits.
iLog=Int(Log10(Sgn(fInput)*fInput+0.0));
iTemp=Round(fInput / (10^(iLog-iDigits+1)));
//return(Log10(fInput+0.0)); //Debugging
fReturn=iTemp*(10^(iLog-iDigits+1));
} //End (Round to significant digits.)
Return(fReturn);
} //End (RSigFig)
</cfscript>
Note: I noticed that on some decimal place numbers like 1.15 when I tell it to round
to two significant figures it rounds down to 1.1 while if I put 1.16 it will round to
1.2. In the cases that I tested where the rounding left only whole numbers I did not
see the problem.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists