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!

pad zeros on the right of a string until len = 5

Status
Not open for further replies.

crogers111

Technical User
Jan 23, 2004
158
US
CRXI
SQL

I'm trying to remove the decimal from a string and then pad the right side with zereos until the string is 5 characters in length.

I have the decimal removal working but my loop is failing and returning an error " A string is requried here". I haven't written a loop before so am hoping it's some simple syntax that I'm missing:



Whileprintingrecords;
StringVar Dx1;

Dx1 := {Command.DiagCode};

if Dx1 <> "" then
//removes the decimal
Dx1 := Replace(Trim({Command.DiagCode}),".","");

if len(Dx1)=5 then
Dx1
else

Do
Dx1 := Dx1 & "0"
While
Len(Dx1) < 5
 

Try adding extraneous 0's to the right, then using the left function to cut off what you need:


if not isnull(command.diagcode) and command.diagcode <> ""
then
left(replace(trim(command.diagcode),".","") + "00000",5)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top