Hello, fellow beginner here.So i am trying to add cash to my game and i want to abbreviate the numbers using suffixes like K for thousand M for million and so on. And i do know that i didnt attempt it it is because i dont know how to, So please help
how to add suffixes to numbers?
2 answers
To put a string after a number, you can use ..
To figure out which suffix you need, you can use a loop and a table.
The logic: If a number is divided by 1000 and it is bigger than 1, it means it's still too big for the current suffix, if you loop this you can easily get the correct suffix.
local List = {
"K","M","B","T","Qd","Qn","Sx","Sp","O","N" --List of your suffixes in order of 1000's
}
function NumberSuffix(Num)
local ListCount = 0
-- while we're not at the correct suffix do
while Num / 1000 >= 1 do
-- increment the suffix from the array
ListCount = ListCount + 1
-- divide the number so we can continue with it.
Num = Num / 1000
end
-- if the initial number was < 1000 return the number.
if ListCount == 0 then return Num end
-- returns the number, with the suffix added at the end
return math.floor(Num*10)/10 ..List[ListCount].."+"
end
local f = NumberSuffix
print(f(5)) --> 5
print(f(1337)) --> 1.3K+
print(f(30203)) --> 30.2K+
print(f(32482348324832)) --> 32.4T+
print(f(248738492384293483294823984234)) --> 248.7O+
2 comments
This will be helpful, as I (an I'm sure many others) would love to add suffixes to our numbers.
This process is called concatenation, and it is used in almost all programming languages. Here is a wikipedia article for further reading if anyone is interested: https://en.m.wikipedia.org/wiki/Concatenation
--Local Script--
local plr = game.Players.LocalPlayer
local cashNum = tonumber(plr.Cash.Value)
if plr.Cash >=1000
plr.Cash = tostring(cashNum/1000).."K"
end
if plr.Cash >=1000000 then
plr.Cash = tostring(cashNum/1000000).."M"
end
If you want to keep going use this
if plr.Cash >= --[[Number you want to convert]] then
plr.Cash = tostring(cashnum/--[[Number you want to convert]])..--Abbreviation
end
also make sure the cash value type is a string or else it won't work.
1 comment
You'd want to use a loop for this. What you're doing now is overcomplicated, you'd never want to do this if you went into 1e99+, take a look at my answer so you'll know a better way of doing this.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Just wanted to point out that you should use suffixes such as when the player is not actively interacting with a GUI Object showing it, I suggest that once the player hovers over the GUI Object that the actual number shows, this will point attention to detail :)
Great (not) idea Chicken, I'll have that upgrade for 133.337.000.000.000.000.000.000 xD