Hello, if i set 100_325_000_000 in my Abbreviation, is return 100T, because i set floor, and without, this return 100.130531,T but me if the number is 100T is return 100,3T and 10T is return 10.32T and is return 1.325T
-- By Lazxr
local suffixArray = {"K", "M", "B", "T", "Qa", "Qi", "Sx", "Sp", "Oc", "No", "Do"} -- Suffixes actuels pour les grandes valeurs
local Abbreviation = {}
function Abbreviation:getFirstDigits(value: number, digits :number)
assert(type(value) == "number", "The value type isn't a number")
local valueString = tostring(math.floor(value))
local firstDigits = valueString:sub(1, digits)
return firstDigits
end
function Abbreviation:getNumberLength(value: number)
assert(type(value) == "number", "The value type isn't a number")
local valueString = tostring(value)
return valueString:len()
end
function Abbreviation:getAbbreviation(value: number)
assert(type(value) == "number", "The value type isn't a number")
local valueLength = self:getNumberLength(value)
local abbreviatedResult
for i, suffix in ipairs(suffixArray) do
local exponent = 10 ^ (3 * i)
local exponentLenght = self:getNumberLength(exponent)
local nextExponentLenght = self:getNumberLength(10 ^ (3 * (i + 1)))
local nextFloatedNumberOfValue = (10 ^ (valueLength - exponentLenght))
if valueLength >= nextExponentLenght then continue end
if valueLength >= exponentLenght then
local abbreviatedValue = (value / exponent * 10) / 10
abbreviatedResult = tostring(abbreviatedValue) .. ",".. suffix
break
end
end
return abbreviatedResult
end
return Abbreviation
and i test this
function Abbreviation:getAbbreviation(value: number)
assert(type(value) == "number", "The value type isn't a number")
local valueLength = self:getNumberLength(value)
local abbreviatedResult
for i, suffix in ipairs(suffixArray) do
local exponent = 10 ^ (3 * i)
local exponentLenght = self:getNumberLength(exponent)
local nextExponentLenght = self:getNumberLength(10 ^ (3 * (i + 1)))
local nextFloatedNumberOfValue = (10 ^ (valueLength - exponentLenght))
if valueLength >= nextExponentLenght then continue end
if valueLength >= exponentLenght then
local abbreviatedValue = (value / exponent * 10) / 10
local notFloatedValue, floatedValue = math.modf(abbreviatedValue)
local getDigit = self:getFirstDigits(floatedValue * (10 ^ nextFloatedNumberOfValue), nextFloatedNumberOfValue)
print(getDigit)
abbreviatedResult = tostring(abbreviatedValue) .. suffix
break
end
end
return abbreviatedResult
end
but the floatedNumber return is 1.3053100000000485e+99