AddLeadingZeros:
Creates a number having a given length, by adding zeros to the front of the number until the length is met.
Description:
The AddLeadingZeros function creates a number having a given length, by adding zeros to the front of the number until the length is met. For instance, if you want AddLeadingZeros to return a six digit number, the totalLength argument would be six and then any number you entered into the first argument would be prefixed by zeros until it was 6 characters in length. If the entered number is greater than totalLength, the number is returned as entered. For instance, if you enter a 1 as the number and 3 as the total length, AddLeadingZeros will return "001". If you enter 1234 as the number and 3 as the total length, "1234" will be returned.
Syntax:
string = AddLeadingZeros(number, totalLength)
Example:
<%
dim displayNum
displayNum = AddLeadingZeros(1234, 6)
'--- returns 001234
%>
ASP Source Code:
<%
Function AddLeadingZeros(byval n, byval count) dim c, s, i if len(n) >= count then addleadingzeros = n exit function end if c = count - len(n) for i = 1 to c s = s & "0" next s = s & cstr(n) AddLeadingZeros = s End Function
%>
|