So I created a number abbreviation system, because I couldn’t seem to find any good ones on youtube or the devforum.
Module With Unnecessary Variables:
local Module = {}
local Abbreviations = {"k", "M", "B", "T", "Qa", "Qn", "Sx", "Sp", "Oc", "N"} -- Number Abbreviations
local f = math.floor --- Rounds down for example 1.99 becomes 1
local l10 = math.log10 -- Checks how many digits are in a number
function Module.AbbreviateNumber(Number: number, Decimals)
return f(((Number < 1 and Number) or f(Number) / 10 ^ (l10(Number) - l10(Number) % 3)) * 10 ^ (Decimals or 3)) / 10 ^ (Decimals or 3)..(Abbreviations[f(l10(Number) / 3)] or "")
end
print(Module.AbbreviateNumber(1.2751232142143e8)) -- 127.512M
print(Module.AbbreviateNumber(1.2751232142143e7)) -- 12.751M
print(Module.AbbreviateNumber(1.2751232142143e6)) -- 1.275M
print(Module.AbbreviateNumber(1.2751232142143e8, 2)) -- 127.51M
print(Module.AbbreviateNumber(1.2751232142143e7, 2)) -- 12.75M
print(Module.AbbreviateNumber(1.2751232142143e6, 2)) -- 1.27M
print(Module.AbbreviateNumber(1.2751232142143e8, 1)) -- 127.5M
print(Module.AbbreviateNumber(1.2751232142143e7, 1)) -- 12.7M
print(Module.AbbreviateNumber(1.2751232142143e6, 1)) -- 1.2M
print(Module.AbbreviateNumber(1.2751232142143e8, 0)) -- 127M
print(Module.AbbreviateNumber(1.2751232142143e7, 0)) -- 12M
print(Module.AbbreviateNumber(1.2751232142143e6, 0)) -- 1M
return Module
Module Without Unnecessary Variables
local Module = {}
function Module.AbbreviateNumber(Number: number, Decimals)
return math.floor(((Number < 1 and Number) or math.floor(Number) / 10 ^ (math.log10(Number) - math.log10(Number) % 3)) * 10 ^ (Decimals or 3)) / 10 ^ (Decimals or 3)..(({"k", "M", "B", "T", "Qa", "Qn", "Sx", "Sp", "Oc", "N"})[math.floor(math.log10(Number) / 3)] or "")
end
print(Module.AbbreviateNumber(1.2751232142143e8)) -- 127.512M
print(Module.AbbreviateNumber(1.2751232142143e7)) -- 12.751M
print(Module.AbbreviateNumber(1.2751232142143e6)) -- 1.275M
print(Module.AbbreviateNumber(1.2751232142143e8, 2)) -- 127.51M
print(Module.AbbreviateNumber(1.2751232142143e7, 2)) -- 12.75M
print(Module.AbbreviateNumber(1.2751232142143e6, 2)) -- 1.27M
print(Module.AbbreviateNumber(1.2751232142143e8, 1)) -- 127.5M
print(Module.AbbreviateNumber(1.2751232142143e7, 1)) -- 12.7M
print(Module.AbbreviateNumber(1.2751232142143e6, 1)) -- 1.2M
print(Module.AbbreviateNumber(1.2751232142143e8, 0)) -- 127M
print(Module.AbbreviateNumber(1.2751232142143e7, 0)) -- 12M
print(Module.AbbreviateNumber(1.2751232142143e6, 0)) -- 1M
return Module