Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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?

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. PreciseLogic 271 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
0
Wow. I didn't expect it to be that simple... shadow7692 69 — 6y
Ad

Answer this question