How can I make it so it does not do 0.00 For abbreviations on Text

Hello! I have a script where it will show abbreviations, but when I have it at 0, it’ll do 0.0, or 100.0, how can I fix this so where it only does it when its at like 100.0QD Or something like that.

local abbrev = {"", "K", "M", "B", "T", "Qd", "Qn", "Sx", "Sp", "O", "N", "de", "Ud", "DD", "tdD", "qdD", "QnD", "sxD", "SpD", "OcD", "NvD", "Vgn", "UVg", "DVg", "TVg", "qtV", "QnV", "SeV", "SPG", "OVG", "NVG", "TGN", "UTG", "DTG", "tsTG", "qtTG", "QnTG", "ssTG", "SpTG", "OcTG", "NoAG", "UnAG", "DuAG", "TeAG", "QdAG", "QnAG", "SxAG", "SpAG", "OcAG", "NvAG", "CT", "INF"}
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

while wait() do
	local player = game.Players.LocalPlayer
	script.Parent.Text = Format(player.leaderstats.Coins.Value,1)
end
1 Like

Have you tried turning normal into an integer?

normal seems to be a float, since you’re dividing by 10^idp (well it would be a float in most cases if the numerator is not divisible by 10^idp).

normal = math.floor(normal)
1 Like

Where do I put this inside the script?

1 Like

helped out on another post a while ago so you can try this

function AbbreviateNumber(Number, Decimals)
    local Suffixes = {"K", "M", "B", "T", "Qd", "Qn", "Sx", "Sp", "O", "N"}

    for Count = #Suffixes, 1, -1 do
        if Number >= 10^(Count * 3) then
            Number = string.format("%."..Decimals.."f"..Suffixes[Count], Number / 10^(Count * 3))
            Number = string.gsub(Number, "%.*0+"..Suffixes[Count], Suffixes[Count])
			
            return Number
        end
    end

    return tostring(Number)
end

I limited it to N because the Max number is close to 4 nonillion(4 * 10^30)

1 Like
local abbrev = {"", "K", "M", "B", "T", "Qd", "Qn", "Sx", "Sp", "O", "N", "de", "Ud", "DD", "tdD", "qdD", "QnD", "sxD", "SpD", "OcD", "NvD", "Vgn", "UVg", "DVg", "TVg", "qtV", "QnV", "SeV", "SPG", "OVG", "NVG", "TGN", "UTG", "DTG", "tsTG", "qtTG", "QnTG", "ssTG", "SpTG", "OcTG", "NoAG", "UnAG", "DuAG", "TeAG", "QdAG", "QnAG", "SxAG", "SpAG", "OcAG", "NvAG", "CT", "INF"}
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

while wait() do
	local player = game.Players.LocalPlayer
	script.Parent.Text = Format(player.leaderstats.Coins.Value,1)
end
1 Like

That did not work, it still does the same thing.

1 Like

Whenever I use the second script I get this error.

that is on your end
has nothing to do with my code at all

besides that is a warning caused by a WaitForChild that you have somewhere


I had something (which I fixed) in my other script, but it still does not work.

what doesn’t work?
not a lot of information here

you didn’t even use the function at all, it is never being called

It says I have 100 coins, but it shows 0. I have no clue why it’s not working I am getting no error. I just put what you gave me.

like I said you aren’t even calling the function at all

while task.wait() do
	local player = game.Players.LocalPlayer
	script.Parent.Text = AbbreviateNumber(player.leaderstats.Coins.Value, 1)
end

you just do the same thing you had up there, simple

I don’t know much about scripting, so I don’t really know what you mean.

full code
function AbbreviateNumber(Number, Decimals)
    local Suffixes = {"K", "M", "B", "T", "Qd", "Qn", "Sx", "Sp", "O", "N"}

    for Count = #Suffixes, 1, -1 do
        if Number >= 10^(Count * 3) then
            Number = string.format("%."..Decimals.."f"..Suffixes[Count], Number / 10^(Count * 3))
            Number = string.gsub(Number, "%.*0+"..Suffixes[Count], Suffixes[Count])
			
            return Number
        end
    end

    return tostring(Number)
end

while task.wait() do
	local player = game.Players.LocalPlayer
	script.Parent.Text = AbbreviateNumber(player.leaderstats.Coins.Value, 1)
end

I recommend learning the basics of lua if the other replies I sent confused you

Alright, I will do that later today cause I really wanna know how to do it. But I got it working, thank you so much, I really do appreciate it!

1 Like