Format 1 to 01, 2 to 02, etc

How can I format a single digit number to 2 digits without a few if statements?
Any built-in thing in lua for this type of formatting?

in C# its:
string.Format("{0:00}", yourInt);
yourInt.ToString(“00”);

(I’m making a countdown clock)

4 Likes
string.format("%0.2i", 2) -- 02

the %0.2i format takes an integer and pads it to a length of 2. %0.3i would pad it to 3.

Similarly, you can do

string.format("%0.3f", 2) -- 2.000

to specify an amount of decimals to follow a given number.

http://wiki.roblox.com/index.php?title=Format_string is a good resource to look up

50 Likes

Savior

4 Likes