Hello!
A way I found working was by firstly formatting %.1f
relative to i
and saving the returned string into a variable like this:
local formatNumber = string.format("%."..(3 * i).."f", number / v)
And then remove the last digits (relative with i too) with string.sub()
like this:
return formatNumber:sub(1, #formatNumber - (3 * i - 2)) .. Suffixes[i], Suffixes
However, to stop “normal” numbers to break the system, one can replace:
if number == 0 then
return 0
end
with:
if number < 1000 then
return number
end
So the function looks like this:
function SuffixNumber(number)
if number < 1000 then
return number -- return all numbers that don't need a suffix instantly
end
local Suffixes =
{ "K", "M", "B", "T", "Qa", "Qi", "Sx", "Sp", "Oc", "No", "Dc", "Ud", "Dd", "Td", "Qad", "Qu", "Sd", "St" }
local i = math.floor(math.log(number, 1e3))
local v = 10 ^ (i * 3) -- a "synonym" of math.pow
local formatNumber = string.format("%."..(3 * i).."f", number / v) -- format the number relative to i
return formatNumber:sub(1, #formatNumber - (3 * i - 2)) .. Suffixes[i], Suffixes -- get the length of the string, cut the last digits and return it
end
There is probably an easier way of doing this, however, this is a way based on the code beforehand.
Hope I could help!