Hello, I have this function that abbreviates numbers and it’s working well apart from when it has a whole number. Instead of displaying the whole number it would displaying something like 10.00, Is there anyway I could modify this so it would just display 10? I thought about using math.round() but this wouldn’t work very well in my case due to the output of the abbreviation function being a string.
local function Format(value, idp)
local ex = math.floor(math.log(math.max(1, math.abs(value)), 1000))
local abbrevs = abbrev [1 + ex] or ("e+"..ex)
local normal = math.floor(value * ((10 ^ idp) / (1000 ^ ex))) / (10 ^ idp)
return ("%."..idp.."f%s"):format(normal, abbrevs)
end
local text = "10.00K"
local numberFromText = string.match(text,"%d+") -- get only the numbers from the text
local convertToNumber = tonumber(numberFromText) -- convert it to a number
print(convertToNumber ) -- Output : 10
local suffixes = {
"",
"K",
"M",
"B",
"T",
"Qa",
"Qi",
"Sx",
"Sp",
"Oc",
"No",
"Dc",
"Ud",
"Dd"
}
local DP = {}
function DP.Abbr(number)
local abbreviationFactor = math.floor(math.floor(math.log10(number)) / 3)
local abbreviation = ""
if abbreviationFactor > 0 then
abbreviation = string.format("%.2f", number / 10 ^ (abbreviationFactor * 3)) .. suffixes[abbreviationFactor + 1]
else
abbreviation = tostring(number)
end
return abbreviation
end
return DP
Usage
local DigitProfiler = require(game.ReplicatedStorage:FindFirstChild("Modules"):FindFirstChild("Digit Profiler"))
Text = DigitProfiler.Abbr(Chips.Value)
This fixes your problem and also allows you to add custom abbreviations if needed. If you want to fix your original script than just add a math.floor to the value.
Judging by the screenshot, this is a rarity collector, meaning that with progression that can very quickly become 1/1… At least do research before being passive aggressive
I’m acoustic. It’s hard for me to see what the tone of a message is, so I interpret it from the language. The smiley is very often used in conjunction with passive aggression.