22
votes

In Crystal Report using Visual Studio 2010, I am trying a to create a formula for the following scenario:

x = any number (Fixed number of 8 digits, cant be less or greater)

If Length of X is less than 8, pad the required amount of 0's in the front to make its length 8.

Eg:

X = 123
Result of Formula should be 00000123

X = 9
Result of Formula should be 00000009

Any help will be appreciated. Thanks in advance.

2
Just a note - you can't have a number with leading zeroes, as zeroes on the left have no mathematical purpose. You will have to convert your number to a string before it can be rendered.Simon MᶜKenzie
Hmm.. yes makes sense in what you say. Might as well use a string then.aMazing
I got it Right("0000"&{MyFieldToPad},8) Works perfectly as I want it to.aMazing

2 Answers

27
votes

ToText({table.field},"00000000") is more succinct.

14
votes

I got it

Right("0000"&{MyFieldToPad},8)

Works perfectly as I want it to.