Pad A Number Field With An Exact Number Of Leading Zeros

October 26, 2005 – 7:43 pm

If you have a number that needs to be padded with leading zeros, this technique does it using Formula language. The same technique (with appropriate syntax changes) can be used in most programming languages.

1
Padded := @Right( "00000000" + @Text(Number); 8)

This example returns an eight-character text string (stored in variable “padded” in this example). This string consists of the original value in the Number field, padded with leading zeros to a total length of 8 characters. For example, Number 123 results in Padded 00000123.

Related posts:

  1. Access Field Names Preceded By ‘$’ With LS
  2. Adjust Date/Time To Next Business Day
  3. Get Rules From Users Mailfile
  4. How to use a list to get around the Array size limit
  5. @Unique Not Generating a Unique Number in Web Applications

  1. One Response to “Pad A Number Field With An Exact Number Of Leading Zeros”

  2. I would consider using @Repeat, makes the changing of the length easier.

    PadLength := 8 ;
    Padded := @Right( @Repeat( “0â?³ ; PadLength ) + @Text(Number); PadLength )

    By Chad Schelfhout on Oct 26, 2005

Sorry, comments for this entry are closed at this time.