# CFLib.org – Common Function Library Project

## TrailingZeroes(inNum, places)

##### Last updated September 27, 2002

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Restores significant trailing zeroes which may have been omitted during calculations. Does not remove excess trailing zeroes (use a rounding function for this).

Return Values:
Returns a number.

Example:

``````<cfoutput>
10.0/2:<br>
#10.0/2#<br>
<br>
TrailingZeroes(10.0/2, 1):<br>
#TrailingZeroes(10.0/2, 1)#<br>
<br>
TrailingZeroes(5.0/2, 1):<br>
#TrailingZeroes(5.0/2, 1)#<br>
<br>
TrailingZeroes(5.00, 1):<br>
#TrailingZeroes(5.00, 1)#<br>
</cfoutput>
``````

Parameters:

Name Description Required
inNum The number. Yes
places Number of significant digits. Yes

Full UDF Source:

``````/**
* Restores significant trailing zeroes which may have been omitted during calculations.
*
* @param inNum      The number. (Required)
* @param places      Number of significant digits. (Required)
* @return Returns a number.
* @author Shawn Seley (shawnse@aol.com)
* @version 1, September 27, 2002
*/
function TrailingZeroes(inNum, decPlaces){
var existing_dec_places  = 0;

if(decPlaces GT 0) {
if(inNum contains "."){
existing_dec_places = Len(ListGetAt(inNum, 2, "."));
if(existing_dec_places LT decPlaces){
return inNum & RepeatString("0", decPlaces - existing_dec_places);
}
} else {
// was shortened to an integer without a decimal point
return inNum & "." & RepeatString("0", decPlaces - existing_dec_places);
}
}
return inNum;
}
``````

### Search CFLib.org

QueryDeleteRows
November 04, 2017

May 11, 2016