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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Padding with zeros 2

Status
Not open for further replies.

lauriesamh

Technical User
Sep 1, 2004
119
US
Hi,
I am trying to easily padd all the numeric fields in a report with zeros for an export. The fields are different lenghts and need to be right justified with zero filling on the left.

Any Ideas to do this very quickly?
 
Try:

ReplicateString("0",10-len(totext(8976,0,"")))+totext(8976,0,"")

Replace the 8976 references with your field, and 10 with the length of the field that you want.

-k
 
Or, try:
ToText({Table.Field},"0000000");

The above would pad each number with up to 7 zeros. For example, if the number was 12345, the result would be '0012345'.

-dave
 
Hi,
Thanks but my problem is that I have to keep the fields numeric and these change to text? Any further ideas?
 
What does and these change to text mean?

You can display using the formula, and base any summaries on the actual field.

Dave's solution is much cleaner, but Crystal doesn't pad a numeric with zeros, because numerics do not have leading zeros.

-k
 
Try wrapping it in a Tonumber command

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
First thanks to all that have replied!

I did try to wrap it up with tonumber and I ended up where I started...

When I tried ToText({Table.Field},"0000000"); it works but my problem is the original field is a currency field so I get for example $00000000.

What I need for example is: $1.37 or (5.25) to be the following:
000137
-00525

I hope this clarifies
 
You're getting the dollar sign based on your Currency field default format. If you want $1.37 to be "0000137" then try this:

ToText(CDbl({Table.Field}) * 100, "0000000")

If you need to use this for summary operations (or something else), just use the above for display, and use the original db field for calculations.

-dave
 
Thanks that worked. I appreciate everyone who helped me figure this out!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top