Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to put 0 in front of any single digit integer?

Say, if I set an integer variable:

local Number = 0

I then set up a loop that adds 1 every second:

while true do
	wait(1)
	Number = Number + 1
	print(Number)

This would output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ....

I want this output to be: 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, ..., where there is a 0 before every number less than 10.

How would I do this?

1 comment

0

You wouldn't be editing the actual number, just the string you are printing. You would simply type print("0"...tostring(Number)). Whenever you wish to incorporate a variables and a string together, use ... in between them.

1 answer

✓ Accepted answer

You could do a simple "if" statement.

local Number = 0

while true do
    wait(1)
    Number = Number + 1
    if Number < 10 then -- if number is less than 10 (1-9)
        print("0"..Number) --Just manually add it.
    else --If number is greater than 10 (10 + )
        print(Number)
    end
end

1 comment

0

Wow. I didn't expect it to be that simple...

This discussion is preserved as it was. New answers, comments, and votes are closed.