Hello there, I am sure that some of you have problems with number abbreviation. Well, I have created a module where you can abbreviate your numbers.
You can get the module from here or just require(6055441479)
How to use it?
Just change the following base code to your own needs!
local module = require(id or in-game module)
local num = 912048021 --This is just an example number we are going to use
print(module.Simplify(num)) --Should print 912M
--another example
local num = 183497821351421241
print(module.Simplify(num)) --Should print 183.4Qa
--Decimal Update Example
local num = 1946692346719857
print(module.Simplify(num, 5)) --Should print 1.94669Qa
--Example 2
local num = 1946692346719857
print(module.Simplify(num, 0)) --Should print 1Qa
--Example 3
local num = 1946692346719857
print(module.Simplify(num)) --Should print 1.9Qa
--Example 4
local num = 9012
print(module.Simplify(num, 4)) --Should print 9.012K
Source code:
local Back = "000000."
local function NumberNeededWarn(n)
warn(n.." is not a valid number. Please enter a number")
end
local function FormatNum(No_)
local a = string.reverse(string.format("%f", No_))
local c = a:sub(Back:len() + 1)
return string.reverse(c)
end
local SimplifyerSign = {
S1 = "K",
S2 = "M",
S3 = "B",
S4 = "T",
S5 = "Qa",
S6 = "Qi",
S7 = "Sx",
S8 = "Sp",
S9 = "Oc",
S10 = "N",
S11 = "Dc",
S12 = "Ud",
S13 = "Dd",
S14 = "Td",
S15 = "Qad",
S16 = "Qid",
S17 = "Sxd",
S18 = "Spd",
S19 = "Ocd",
S20 = "Nod",
S21 = "Vg",
S22 = "Uvg",
S23 = "Dvg",
S24 = "Tvg",
S25 = "Qavg"
}
local module = {}
function module.Simplify(No_, deci)
local d = FormatNum(tostring(No_))
local Length = tonumber(#d)
if deci == nil then
deci = 1
else
end
if tonumber(d) then
if Length then
if Length > 3 then
local a = math.floor((Length - 1)/3)
local sign = SimplifyerSign["S"..a]
local b = math.floor(No_/10 ^ (a * 3 - deci))
return (b/(10 ^ deci))..sign
else
return tostring(No_)
end
else
end
else
NumberNeededWarn(d)
return "NaN"
end
end
return module
Edit: Made some changes with @Gojinhan feedback. And also added a feature to calculate the number of decimals you want!
Edit2: Changes with @Blockzez feedback