Tuesday, March 6, 2012

Add leading Zeros to integer?

I need to cast an integer to a string to append to another string for a barcode.
How can I get 1 -> '0001' OR 100 -> '0100'
Any suggestions?
Mike BAs long as they are all positive numbers, you can use:SELECT Replace(Str(1, 20), ' ', '0')If you need to cope with negative numbers, I'd recommend using a short function... It is cleaner.

-PatP|||As long as they are all positive numbers, you can use:SELECT Replace(Str(1, 20), ' ', '0')If you need to cope with negative numbers, I'd recommend using a short function... It is cleaner.

-PatP
Thanks that was what I was looking for.

Mike B

No comments:

Post a Comment