How to turn amount of digits to Zeros?

Hi, how can I turn an amount of digits into 0’s?

For example, if I have the number “2”, How can I take that 2 and make it into Two 0’s.
So e.g. 2 = 00.
E.g. 3 = 000 (3 Zeros)

There’s probably a better way but off the top of my head a simple for loop would work.

local x = “”

for i = 1,num,1 do
     x = x .. “0”
end

With num being the target value and you can do tonumber(x) if you need a numeric value.

The more idiomatic approach is ("0"):rep(n) or string.rep("0", n)–where n is an integer of the amount of zeros you wish to have.

Thank you, how would I attach it the string.rep(“0”, 3) to a number? e.g. to make 1 into 1000 with string.rep(“0”,3)?

Use string concatenation

local zeros = 3
local number = 1 .. string.rep("0", zeros) --becomes 1000
1 Like

A for loop would be the simplest way.