Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikmark1990
Contributor III
Contributor III

Add leading zeroes to a variable

Currently I have this loop that has the output:


1

2

3

4

5

6


FOR vraagNummer = 1 TO 6


TRACE $(vraagNummer);


NEXT


How can I add leading zeroes to the variable to get the output :


001

002

003

004

005

006


In other topics I only read about leading leading zeros to fields instead of variables. If the loop goes further than 10 I'd like to get :


010

011 ect. untill 999

....

999

1 Solution

Accepted Solutions
benoitgochel
Contributor III
Contributor III

Hi Mark,


Try something like this :

if(vraagNummer > 99) then

    SET output = $(vraagNummer );

    elseif (vraagNummer > 9) then

    SET output = 0$(vraagNummer );

    else

    SET output = 00$(vraagNummer );

endif;


Hope that helps.

Best regards

View solution in original post

2 Replies
benoitgochel
Contributor III
Contributor III

Hi Mark,


Try something like this :

if(vraagNummer > 99) then

    SET output = $(vraagNummer );

    elseif (vraagNummer > 9) then

    SET output = 0$(vraagNummer );

    else

    SET output = 00$(vraagNummer );

endif;


Hope that helps.

Best regards

Anonymous
Not applicable

Hello,

Try this:

FOR vraagNummer = 1 TO 6

     Let Number = Num($(vraagNummer), '000');

     TRACE $(Number);

NEXT