How do you add the zero back to the first character of a number value?

Quick question i am having a hard time with; Its in the title not gonna repeat it again.

Methods that i tried to get the zero back.

– I tried this method
local number = 010000
print(number) – result: 10000 (where the zero go???)

– Also tried this method
number = tostring(number)
number = “0” … number
number = tonumber(number)
print(number)

– I want it to be 010000… thoughts?

Trying to find out how to get the zero back since it is very important for what I am trying to do.

I really want it to be a number and not strings for reasons. Also im mainly gonna be using tonumber() for what im trying to do.

Hopefully this is enough for you to understand what i am trying to convey.

2 Likes

It just instantly corrects that because well you can have a 0 precede any number

you prlly have to go with a string

1 Like

Is it really the only way? if so then i will just resort to using strings.

1 Like

Yea, that’s just a general number rule

You might have to do that

This is a very odd question. You could make that a string to show the zero. But if you’re doing math with a number, it will act like math…

The 0 doesn’t matter when the value is of type number, because 0x == x. However if you want to convert the number to a string(assuming you want to print it in a cool manner or show it somewhere), with preceding zeros, you can use the following code:

local n = 6 --amount of preceding zeros
local f = "%0"..n.."d" --string format

local x1 = 10000 --input 1
local x2 = 123 --input 2

print(string.format(f, x1)) --010000
print(string.format(f, x2)) --000123
2 Likes

For more context; It is for converting data like Vector3’s and stuff to something saveable and very compressed (a bit too compressed, making it too hard for myself)

the first two numbers are what type of data it is, and the proceeding numbers are information stored in data type. For example

local table = {
[“01”] = “Type”,
[“02”] = “Another Type”,
–[[

keeps on going till the double digits because
alotta data types

]]
}

– so if the number is
local number = 01001110

– first two numbers are 01, which means it is the type “Type”
– and the other numbers are just true or false, 0 for false, 1 for true.

table variable is just a dictionary for reference on what number is connected to which.
only doing this because i heard that numbers take up less storage than strings. (maybe a bit too much compression but im finding it out the hard way)

Its fine if the first question is not possible, atleast tell me if numbers take up less storage than strings statement is actually true.

[“01”] = “Type”,
[“02”] = “Another Type”,

These are no longer numbers … they are strings.