Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting number with leading zeros

Status
Not open for further replies.

dgillz

Instructor
Mar 2, 2001
10,038
US
I have a number 1234.56 for example, and I need the total length to be 18 characters with leading zeros. In other words, "000000000001234.56".

I currently have a formula that works by converting my number to a string using totext(), then calculating the number of leading zeros I need based of the result and then concatenating them to the front of the string. But I am thinking there is an easier way. Any insights appreciated.

Software Training, Implementation, Programming and Support for Macola Progression, Macola ES, Synergy, and Crystal Reports. Check out our Macola tools:
 
Many thanks. I have lost a lot of my crystal skills over the past several years.

Software Training, Implementation, Programming and Support for Macola Progression, Macola ES, Synergy, and Crystal Reports. Check out our Macola tools:
 
In general,

1) if you need leading or trailing zeros, you don't have a NUMBER (although the destination user may convert your string with leading or trailing zeros to a number in their system) you have a STRING. You will not be using this value with leading and trailing zeros, to perform arithmetic.

2) if your 'number' is used as a name for something like a part or an invoice or a person or a place, your 'number,' a part number, invoice number, social security number, employee number, postal code, are 'numbers' on which no arithmetic operation would ever logically be performed. They are IDENTIFIERS and ought to be STORED and treated as STRINGS.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top