Abbreviated leaderboard doesn't work at to high numbers

I’ve followed a tutorial on youtube but it doesn’t seem as it works on numbers above 100T then it returns 100000000.0K again. Any wonders why? Here is the code

local player = game.Players.LocalPlayer

local NumeralDictionarys =
{
K = 4,
M = 7,
B = 10,
T = 13,
q = 16,
Q = 19,
s = 22,
S = 25,
O = 28,
N = 31,
D = 34
}

while wait() do
local Number = tostring(math.floor(player:WaitForChild(“MoneyFolder”).Money.Value))
local chosenAbbreviation

for NumeralDictionary, digits in pairs(NumeralDictionarys) do
	if #Number >= digits and #Number < (digits + 3) then
		print(NumeralDictionary)
		chosenAbbreviation = NumeralDictionary
		break
	end
end

if chosenAbbreviation ~= nil then

	
	local digits = NumeralDictionarys[chosenAbbreviation]
	local rounded = math.floor(player.MoneyFolder.Money.Value / 10 ^ (digits - 2)) * 10 ^ (digits - 2)
	script.Parent.Text = string.format("%.1f", rounded / 10 ^ (digits - 1)).. chosenAbbreviation
else
	script.Parent.Text = Number
end

end

2 Likes

Please surround code you post with backticks
```
like this
```
so it shows up

like this

Anyways, tostring on large numbers will give you non-numerical answers sometimes:

print(tostring(100000000000000)) -- prints '1e14'

That might be your issue.

You can fix this by operating on the number instead of the string:

You’d use that like:

script.Parent.Text = Abbreviate(player:WaitForChild("MoneyFolder").Money.Value)
1 Like