CFLib.org – Common Function Library Project

RoundSigFig(fInput, iDigits)

Last updated October 24, 2003

author

jason snyder

Version: 2 | Requires: CF5 | Library: MathLib

Description:
Rounds a number to a specified number of significant digits.

Return Values:
Returns a numeric value.

Example:

<CFSET iOrigNo=10.5660>
<cfoutput>
Original=#iOrigNo#<br> 
After RoungSigFig=#RoundSigFig(iOrigNo, 4)#
</cfoutput>

Parameters:

Name Description Required
fInput Number to round. Yes
iDigits Number of significant digits to return. Yes

Full UDF Source:

/**
 * Rounds a number to a specified number of significant digits.
 * 
 * @param fInput 	 Number to round. (Required)
 * @param iDigits 	 Number of significant digits to return. (Required)
 * @return Returns a numeric value. 
 * @author jason snyder (jason.snyder@trw.com) 
 * @version 2, October 24, 2003 
 */
function RoundSigFig(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=evaluate(iTemp*(10^(iLog-iDigits+1)));
  } //End (Round to significant digits.)
  Return(fReturn);
} //End (RSigFig)
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