So this is my number Abbreviation Module…
local AbbreviateNumber = {}
local abbreviations = {
K = 4,
M = 7,
B = 10,
T = 13,
QD = 16,
QT = 19,
SXT = 22,
SEPT = 25,
OCT = 28,
NON = 31,
DEC = 34,
UDEC = 37,
DDEC = 40
}
function AbbreviateNumber.Abbreviate(Number)
local Text = tostring(math.floor(Number + 0.5)) -- rounds to nearest whole number
-- We can find the numbers of characters in a text by doing #Text , where "Text" is the text you are using
if #Text > 4 then
Text = Text:sub(1, #Text-4)
for Letter, Number in pairs(abbreviations) do
if Number <= #Text and Number+3 > #Text then
if Number == #Text then Number = #Text-1 end
Text = Text:sub(1, #Text-Number) -- We get the digits that we need in order to shorten the text
Text = Text .. Letter .. "+" -- This will be the shortened version
break
end
end
end
return Text
end
return AbbreviateNumber
Small numbers (under e+15 is fine) but when I call that function and told it to abbreviate lets say , 9e+306 .
My module return string that is so far off. I think the problem is because my module is calculating the text length.
local m = require(game.ReplicatedFirst.Abriviate)
local value = 9e+306
local storedValue = value ~= 0 and math.floor(math.log(value) / math.log(1.0000001)) or 0 ---- (FOR DATASTORE)
local retrievedValue = storedValue ~= 0 and (1.0000001^storedValue) or 0 ---- (FOR INGAME)
print(m.Abbreviate(retrievedValue))
that is a server script calling that module tu abbreviate retrievedValue.
It returns 8QD+ which is so far off.
Can someone help me figure this out?