Skip to main content
Inspiring
July 8, 2009
Question

Leading Zeros

  • July 8, 2009
  • 2 replies
  • 2600 views

I have a field labeled itemNo defined as nvarchar 50 in table on sql server.

On the form, when they enter the itemNo, I need it to be 00010, alsways 5 digits with leadgin zeros, because I have to use that as an exact match in a search later on. Most of the time, they only enter 10 and my search fails.

How do I automatically add the leading zeros to the form variable.I suppose I can check for length and insert it with the leading zeros, but I am using the form variable to check, so I would like that to have leading zeros.

Thanks

    This topic has been closed for replies.

    2 replies

    Dileep_NR
    Inspiring
    July 13, 2009

    <cfset nextid=NumberFormat(nextid,"0000")>

    refer

    http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functa48.htm

    Inspiring
    July 8, 2009

    If the values is always numeric, one option is to use NumberFormat() with a mandatory digit mask

    #NumberFormat(form.someValue, "00000")#

    Inspiring
    July 8, 2009

    another way

    newnum = right("00000" & oldnumber, 5);