Format a number - please help me

Results 1 to 3 of 3

Thread: Format a number - please help me

  1. #1
    Tonya in Florida Guest

    Default Format a number - please help me

    Hi,<BR><BR>I&#039m not sure how to go about writing a function or subroutine for that matter. I&#039ve searched various sites without success in finding good examples. I need to format a number (user input from a html form) e.g. 9711970. This number needs to be formatted to represent 97-0011970 ...where the prefix consists of two digits and a hyphen, and the rest is seven digits long where 11970 must be padded with leading zeros to make up the total of seven digits. Any help would be appreciated. THanks.

  2. #2
    Join Date
    Dec 1969

    Default RE: Format a number - please help me

    This code is approximate, just use it as a guideline.<BR><BR>dim frmNumber<BR>dim leftNumber<BR>dim rightNumber<BR>dim finalOutput<BR>frmNumber = request.form("&#060;formItem&#062;")<BR>leftNumber = left(frmNumber, 2)<BR>rightNumber = mid(frmNumber, 3)<BR>do while len(rightNumber) &#060; 7<BR>rightNumber = "0" & rightNumber<BR>loop<BR>finalOutput = leftNumber & "-" & rightNumber

  3. #3
    KPW Guest

    Default RE: Format a number - please help me

    &#060;%<BR>Dim iSuffix &#039 --- the last digits (i.e., 11970) ---<BR>Dim sSuffix &#039 --- iSuffix converted to a string ---<BR><BR>&#039 --- determine the value of iSuffix ---<BR>... &#039 I assume you already have this part down<BR><BR>sSuffix = CStr(iSuffix)<BR>if Len(sSuffix) &#060; 6 then<BR> sSuffix = "0" & sSuffix<BR>end if<BR>if Len(sSuffix) &#060; 7 then<BR> sSuffix = "0" & sSuffix<BR>end if<BR><BR>&#039 --- sSuffix should now look like "0011970" ---<BR>%&#062;<BR><BR>Yes, this means that now your last seven digits are a string instead of a number. I don&#039t know if you require that it be a number. However, if it has to be a number then I&#039m not sure if there&#039s a way to display leading zeros.<BR><BR>I guess another way to do it would be:<BR>&#060;%<BR>&#039 --- going off the code above ---<BR>if iSuffix &#060; 100000 then<BR> sSuffix = "0" & CStr(iSuffix)<BR>end if<BR>if iSuffix &#060; 1000000 then<BR> sSuffix = "00" & CStr(iSuffix)<BR>end if<BR>%&#062;<BR><BR>Let me know if this gets you anywhere.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts