Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Leading Zeros

Participant ,
Jul 08, 2009 Jul 08, 2009

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

2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 08, 2009 Jul 08, 2009

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

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 08, 2009 Jul 08, 2009

another way

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 12, 2009 Jul 12, 2009
LATEST

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

refer

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources