Hello! I am currently working on a simulator game. I need to abbreviate a number value which will then be applied to a TextLabel. Here is the abbreviation code I made that I need to connect to a number value
local RS = game:GetService("ReplicatedStorage")
local mainFrame = script.Parent
local rebirthFolder = RS:WaitForChild("RebirthsFolder"):FindFirstChild(mainFrame.Name)
local Abbreviations = {
"";
"K";
"M";
"B";
"T";
"Qd";
"Qn";
"Inf";
}
local function AbbreviateNumber(Number)
for i = 1, #Abbreviations do
if Number < 10 ^ (i * 3) then
if Abbreviations[i] == "Inf" then
return "Inf"
else
return math.floor(Number / ((10 ^ ((i-1) * 3)) / 100)) / (100) .. Abbreviations[i]
end
elseif tostring(Number) == "Inf" then
return "Inf"
end
end
end
while true do
wait()
script.Parent.Text = ""..AbbreviateNumber(rebirthFolder:WaitForChild("Amount").Value)
script.Parent.Text = ""..AbbreviateNumber(rebirthFolder:WaitForChild("Cost").Value)-- Replace the Strength with your current leaderstats
end
My problem is finding time to build because of my studies and work. So if it’s something for a short period of time, a big project or something like that. I won’t be able to finish the build.
function aberviate(number)
local abreviations = {
[3] = "K",
[6] = "M",
[9] = "B",
[12] = "T",
[15] = "Qa",
[18] = "Qi",
[21] = "Sx",
[24] = "Se",
[27] = "Oc",
[30] = "Nn"
}
if number < 1000 then
return number
elseif string.find(tostring(number),"e+") then
local split = string.split(tostring(number),"e+")
if split[1] and split[2] then
local power = tonumber(split[2])
if power then
local abreviation = power - (power % 3)
local truepre = tonumber(split[1])
if truepre then
local preAb = tostring(truepre * (10^(power-(abreviation)))) .. " "
return preAb .. abreviations[abreviation]
end
else
return number
end
end
elseif not string.find(tostring(number),"e+") then
local num = tostring(math.floor(number))
local length = #num
local trueLength = #num % 3
if trueLength == 0 then
trueLength = 3
end
local abreviation = abreviations[length-trueLength]
if abreviation then
local startNum = string.sub(num, 1, trueLength) .. "."
local decimals = string.sub(num, trueLength+1,trueLength+2) .. " "
if startNum and decimals then
return startNum .. decimals .. abreviation
else
return number
end
else
return number
end
end
end
By the way, I may as well point out that you don’t really need inf. Any number above (2^1024)-1 which is approximately equal to 1.79*10^308 will automatically count as inf
Right now, I have a script to take a number value and plug it into the parts in the TextLabel that I want. I need those number values to be abbreviated when put into the TextLabel. I can send you the script. Maybe I should make it a string