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

leading zeros for integer variables?

Status
Not open for further replies.

kentara

Programmer
Apr 13, 2005
38
0
0
US
Is there any way to insert a leading zero for integers that are less than or equal to 9?

I am hoping to create a "for" loop that increments integer variable "i", however it needs to increment in this way:
00
01
02
03
04
05
06
07
08
09
10
...
99

The reason for this is that I will be using each value of "i" to create a filename each time the loop is entered. For example, if i=08, I will need to use that to specify a filename (such as "SectionD08").

Any ideas?
 
Is there any way to insert a leading zero for integers that are less than or equal to 9?"

I think your solution lies within your question. Can you see it? :)

frozenpeas
 
Nope, I can't. Try as I might, I can't get an integer value to start with a zero if it's greater than zero (two significant digits? i.e. 01 through 09) And I can't get away with using strings in my program.
 
dont really see your problem, however

Code:
Math.addZeros = function(num){
	if (num<10){
		added = "0" + num;
		return added
	}
	else{
		return num
	}
}

for (mynum =1;mynum<15;mynum++){
	trace(Math.addzeros(mynum))
}

may be close to what you are looking for
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top