I’ve looked around the dev forum and haven’t been able to find what I’ve been looking for so I decided to make my own post.
Is it possible to change how long a value can be dependent on the length of it?
The reason I am using String.Format is so that it doesn’t appear in scientific notion as I’m using very small decimal numbers if there is another way that’s easier I would also like to know.
Here’s part of the code there’s a comment where Im asking the question
for rankInLB, dataStored in ipairs(KillsPage) do
--local thing = dataStored.value /10000000
--if dataStored.value /10000000 < 0.000000000 then thing = string.format("%.15f",dataStored.value /10000000) end
local number = string.len(dataStored.value)
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local Kills = dataStored.value /10000000000
local template = script.Template:Clone()
template.Name = name .. "Leaderboard"
template.PlrName.Text = name
template.Rank.Text = "#" .. rankInLB
template.Kills.Text = string("%.xxxxf",Kills)-- I want to replace xxxx here with the value of number
template.Parent = script.Parent
end
with string.format I can limit the length of a number
and example is like this: string.format(“%.5f”, 0.11111111111111111111111111111)
that would limit the number 0.11111111111111111111111111111 to the fifth decimal place or 0.11111
what I want to do is make it so that I can find the length of the number and replace the 5 that I used with how ever long the number is. The reason for this is so that it doesn’t appear in scientific notation.
Im pretty much just trying to find the equivalent of doing “%0.f” but for a decimal instead of an integer
the numbers im using are never infinitely long I just need a way to show the number without scientific notion
Edit: wait let me test something ill come back to you after
maybe I put it in my code wrong but with it the input is a million times larger than its supposed to be
can you show me how I would put it in the code I showed in the original topic incase I did it wrong?
after some tinkering I found out you were right it’s just that %f isn’t infinite and instead only goes up to about 7 decimal places. I fixed it by putting %.20f instead and then removing the 0’s with gsub. thanks for your help.
before I mark you as the solution I was wondering if it was possible to remove the . at the end of numbers that don’t have a decimal place?
In string pattern matching, . is a “magic character” that represents a character class that contains all characters. When you want to search for . itself, you can escape it using %.
local noTrailingZeroesOrUselessPoint = string.gsub(formattedNumber, "%.0*$", "")
for anyone in the future looking at this forum I found a better solution that also gets rid of any pesty little 00000000000000001’s or 99999999999998’s that you might have at the end of your code.
if number < 1 then
local thing = number
while thing < 1 do
thing = thing*10
f = f + 1
end
end