How do I Display an IntValue in 1k, 2k, 3k and soo on?

i’d go around this by not changing the intvalue at all and making an algorithm that changes the text according to the intvalue. i’d do this by checking if the cash is above 10^x which is when i’d start using the prefix associated with it (if above 10^3 aka 1000, start using k and if above 10^6 or millions start using m) and dividing the intvalue by their respective power (e.g if intvalue is 1200, divide by 10^3). if this sounds too complicated thats because it somewhat is due to the fact this way is purely mathematically based.

example:

local cashString = tostring(cashValue) --cashValue is a placeholder for how much cash we have
local prefix = -- insert prefix here
local power = 0 --current exponent

if cashValue > 10^3 then
 power = 10^3
 prefix = "k"
 cashString = tostring(cashValue / power) .. prefix
elseif cashValue > 10^6 then 
 power = 10^6
 prefix = "m"
 cashString = tostring(cashValue / power) .. prefix
-- and so on.

QUICK SIDENOTE: i just realized that each new prefix comes with every three, so you can make a table and check if the number is larger than 10^(x+3). a good example is that 10^3 is thousands. 10^6 is millions, 10^9 is the billions and 10^12 is a trillion

1 Like

Kinda understand what u mean, but can u implement it in my script and show it to me pls?

1 Like

here it is i use it for my game:

local value = script.Parent.Value -- your value HERE
local textLabel = script.Parent -- your label

local function formatNumber(number)
  if number >= 1000000000000 then
    local formatted = tostring(math.floor(number / 1000000000000)) .. "t"
    return formatted
  elseif number >= 1000000000 then
    local formatted = tostring(math.floor(number / 1000000000)) .. "b"
    return formatted
  elseif number >= 1000000 then
    local formatted = tostring(math.floor(number / 1000000)) .. "m"
    return formatted
  elseif number >= 1000 then
    local formatted = tostring(math.floor(number / 1000)) .. "k"
    return formatted
  else
    return number
  end
end

value.Changed:Connect(function(newVal)
       textLabel.Text = formatNumber(newVal)
end)
4 Likes

there i edited it in a script for you to copy or something

imma try ur script real quick! btw, um wdym? by exponent?

1 Like

All you need is a single google search. Please do that before posting anything here. How do I shorten this numbers? - #8 by nicemike40

1 Like

Sorry, i tried google searching and searching here on the forum, but i just couldnt get the right words to search.

1 Like

could u try mine, i use it for my game and sure will work!

2 Likes

Wait a second, imma try @neweve2323 this guy "“how i shorten this numbers”
then imma try urs. Also, thanks for the help!

yo, imma try urs @IRoastToaster

1 Like

So I tried yours, @IRoastToaster and it works! can u pls modify ur scirpt so that it can even work for millions, billions and trillions?

2 Likes

there i edited the solution, you can add it

2 Likes

hey, I got one last question, how do I do the same for my leaderstats.Cash.Value?
And is that Even possible? @IRoastToaster

local nots = {"K","M","B","T","Qd","Qn","Sx","Sp","O","N"} -- i stole this
function shorten(num)
    local notation = ""
    for _, _not in next, nots do
        if (num / math.pow(10, _ * 3)) >= 1 then notation = _not end
    end
    local front = (#tostring(num) % 3 == 0) and tostring(num):sub(0, 3) or tostring(num):sub(0, #tostring(num) % 3)
    return front .. notation
end

print(shorten(6942069420)) -- 6b

shorter but you can keep the guy earlier as the solution*

Yes it is, all you have to do is change local value = script.Parent.Value to local value = player.leaderstats.Cash.Value make sure to make a player variable too

1 Like

and make sure Cash.Value is a StringValue instance otherwise it would throw an error expecting number but given string blablabla

Bro i tried doing the same thing with leaderstats, like i thought making a local script which fires an event when the cash.value changed then made a seperate server script which on that event fired makes the value of the leaderstats.cash.value to 1k, 2k. But it didnt work.
Pls Help bro, how do I implement ur script in my game? Should I put ur script in my leaderstats script or make a seperate one?
@IRoastToaster

1 Like

the value being 1k 1.2k etc, should only be client side, u dont have to worry and make a remote event and fire, the player that is playing the game should see his cash and not the whole server! just put my script in a LocalScript in the TextLabel GUI you made and change the first line of my script to

local player = game.Players.LocalPlayer
local value = player.leaderstats.Cash
1 Like

but me want the whole server to know. Can u do that please?

oh, do you mean like the people using leaderboard seeing the value of the cash 1k and not 1000?

i think the cash value should be a stringValue @p49p0 mentioned

if changing the cash to a stringValue will kinda ruin then i will be right back

1 Like