How can we do put a number to 3number
-
How we can transform 3 into 003
12 into 012.... -
I haven't tested it but try something like this:
function zeroPadInt(integer, padLen) result = str(integer) while len(result) < padLen loop result = "0" + result repeat return result
Then you can do:
print(zeroPadInt(3, 3)) -
I don't know of a built in function, but you could make one along the lines of:
function longNumber(number,digits) text = str(number) while len (text) < digits loop text = "0"+text repeat return text
-
@Richard Great minds think alike!
-
@pianofire if only I could type faster.
-
Thank you so much,
I'm still not comfortable with the functions, I will try to understand them and I will put them in my program -
I understand your functiont, they are the same
-
For my project digits or padlen must be equal to 3
-
So you could just have a function:
function zeroPadInt(integer) result = str(integer) while len(result) < 3 loop result = "0" + result repeat return result
But in another project you may need a different length so the first version has more reuse value
-
One thing that Petit Computer did was allow multiplying of strings. For instance...
myvar = "01" * 4
This would result in "01010101". Would be nice if that sort of feature were added.
-
Though Petit Computer may provide this feature, I don't believe I've seen this feature in any other languages. It's really just as easy for you to write a simple function that does the same thing.
function appendCopy( str, times) String appendCopy = str for i = 0 to times loop appendCopy = appendCopy + str repeat return appendCopy String newString = appendCopy("01", 4)
BTW, I've not tried appendCopy += str which might also work. But, even if I got something not quite right, you get the idea.
-
TIP: if you put 3 back ticks ``` around a block of code it will format it:
-
@pianofire, Thanks! I also see now that there is a "code" option in the above content choices... dah! : )