I want to add a 0 behind a number x amount of times
Example:
local number = 53
local paddingDigits = math.random(3, 5)
-- Assume paddingDigits is 4, I want this:
number = 000053
-- Assume paddingDigits is 3, I want this:
number = 00053
If this is for sorting, this method will probably work better, as adding a constant number of zeroes irrespective of how many digits a number has will cause some issues when sorting alphabetically.
Example of constant leading zeroes
-- Sorted alphabetically when the number of leading zeroes is always 3
0001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
0002
00020
00021
Note that 0001 and 0002 are not next to each other.
Example of constant number length
-- Using the same numbers as in the previous example
0001
0002
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
Note that using this format, 0001 and 0002 are the first two elements and 0010 only comes after 0002. (Or 0009 if we had it here)
If on the other hand you’re sorting based on value of the number itself, adding leading zeroes isn’t useful.
I do not understand what you mean, @C_Sharper’s example adds a fixed amount digits behind the number and your code is doing the same thing. I have a limit on how many digits a number can have so there will be no case where a number has a higher length than 5.