For a few days now, I have ran into an issue where I needed to set a max limit of 999.99b because once I go past that, the converting function becomes a bit weird.
The issue is that I’m unable to get numbers like 999.99t and 1t (it becomes 1000t and 1000b), and so on.
Was wondering if anyone could look into this for me as I could really use some help on this issue.
I was originally planning to go as high as 10^30 (or even higher for that matter) without it being formatted incorrectly.
Thank you!!
function Functions:AbbreviateNumber(Number)
local Abbreviations = {
{10^30, "o"},
{10^27, "sp"},
{10^24, "sx"},
{10^21, "qn"},
{10^18, "qd"},
{10^15, "t"},
{10^9, "b"},
{10^6, "m"},
{10^3, "k"}
}
for _, abbr in ipairs(Abbreviations) do
if Number >= abbr[1] then
local formattedNumber = string.format("%.2f", math.floor(Number / (abbr[1] / 100)) / 100)
formattedNumber = string.gsub(formattedNumber, "%.?0+$", "") -- // Remove trailing zeros
return formattedNumber .. abbr[2]
end
end
return tostring(Number)
end