local stringNumber = "921028090102102802201601203203102205070150101703103903602102805019031012010120901302201014031020503303109150501403102401070270160120310190103102023021028012050330"
local realNumber = tonumber(stringNumber)
print(realNumber) -- prints out 9.210280901021028e+161
Just print the stringNumber instead of printing the realNumber, since you have quotations it will print as a string, but since its just a number, you dont need the quotations.
Also to add on, you will have an overflow of data with this big of a number- so it wont be precise and instead use scientific notation to abbreviate.
local stringNumber = “921028090102102802201601203203102205070150101703103903602102805019031012010120901302201014031020503303109150501403102401070270160120310190103102023021028012050330”
This Is not a number and if it was it would be wrote as 9.210280901021028e+220.
You may have problems reading that but the program will not.
You can’t keep this a number as it never was a number…
In number form it is so big the program has to use a formula to show it, aka; Scientific Notation. Which is basically the number showen multiplied by the power of 10, X amount of times.
So that number really isn’t a 9.210… that is part of the formula to the real number, the latter being e+220. Meaning you can’t just format the string to get the real number.
There is nothing wrong with the program’s or Roblox’s logic …
Lua stores all number values as floats, and floats do not have the capability to store this number at full precision. You will either have to sacrifice the least significant digits or store it as a string.
There are Lua libraries that allow for arbitrary precision integer representation manipulation. Here is one of many.
Thank you guys for your explanations! That library would come in really handy. Only problem is that I never did something like this. I have no idea how to use it.
Not sure what you’re really doing … So here is a wild guess.
A little math trick workaround, to address floating-point precision errors.
function SnapToGrid(value, gridSize)
local correctedValue = math.round(value / gridSize) * gridSize
return correctedValue + 0.0000000001
end
this: + 0.0000000001 somehow fixes it.
function CorrectPrecision(value, precision)
local factor = 10^precision
return math.round(value * factor) / factor + 0.0000000001
end
--use:
local position = 1234567.123456789
local corrected = CorrectPrecision(position, 6)
print(corrected) -- Outputs: 1234567.123457
I guess this is a way to keep the number within reach for Roblox with the least amount of being off. At that point is like a planck length…
I’m trying to store letters inside an Ordered Data Store. I made a custom letter to number converter for it. That’s why I need the exact number. Otherwise some letters will be different.
Sweet, I love encryption… How did you ever end up with a number that big out of 256 chars.
Going Unicode on us?
function LetterToNumber(letter)
return string.byte(letter)
end
function StringToNumber(text)
local result = {}
for i = 1, #text do
table.insert(result, LetterToNumber(text:sub(i, i)))
end
return table.concat(result, ",")
end
function NumberToString(encodedText)
local numbers = string.split(encodedText, ",")
local text = ""
for _, num in ipairs(numbers) do
text = text .. string.char(tonumber(num))
end
return text
end
local text = "You have got to test everything before you post it and you know this!"
local encoded = StringToNumber(text)
print(encoded)
local decoded = NumberToString(encoded)
print(decoded)
I’m trying to save bio’s that people made which contains a lot of letters. I tried typing a longer text into your work and I got the scientific notation again with an error to it.
My bad… That’s what I get for not testing first. Should work now.
This converts the letters to their char values. Basically the 1st step to encryption. What this needs now is a variant. Like say 22, with that you could add 22 to each outcome for each letter. Then subtract 22 from each letter outcome when decrypting. All in all this is rather weak encryption but, It will stop 99% from figuring it out. Perfect for your purpose. Or leave it as is if you don’t wish to encrypt other than the number conversion…
I did a bit of research on encryption in Roblox … I’m not sure if encryption would break terms of service or not. You might want to check before using this.