truncNumber(input[, decimals])
Last updated June 15, 2006
Version: 1 | Requires: CF5 | Library: MathLib
Description:
Cuts a number to a certain amount of decimal places without rounding.
Return Values:
Returns a number.
Example:
<cfoutput>#TruncNumber(3.646)#</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
input | Decimal number. | Yes |
decimals | Number of decimals to the right of the period. Defaults to 2. | No |
Full UDF Source:
/**
* Cuts a number to a certain amount of decimal places without rounding.
*
* @param input Decimal number. (Required)
* @param decimals Number of decimals to the right of the period. Defaults to 2. (Optional)
* @return Returns a number.
* @author Tony Monast (tony@ckm9.com)
* @version 1, June 15, 2006
*/
function truncNumber(input) {
var decimals = 2;
var regex = "";
var st = "";
if(arrayLen(arguments) EQ 2) decimals = arguments[2];
regex = "^\d*(.\d{1," & decimals & "})?";
st = reFind(regex,input,1,true);
return mid(input,st.pos[1],st.len[1]);
}
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