Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to shorten money value 1000000 to 1M?

Asked by
PolyyDev 214 Moderation Voter
7 years ago

I have a game and I want the number to be 1.5M instead of 1500000. I don't want to put commas in because that maxes out a 1 Quadrillion so I want to use letters after the numbers. If my explaining is horrible, thats what my irl friends say, then I mean just like case clicker

Would this work?

01local value = script.Parent.Text
02 
03function changeNumber(int)
04    if tonumber(int) > 1000 then int.Text = 1K
05    --// Other stuff
06end
07 
08while true do
09    changeNumber(value)
10    wait(1)
11end
0
So is value already 125000 or is it 12.5k? raspyjessie 117 — 7y
0
It is 125000 PolyyDev 214 — 7y

2 answers

Log in to vote
1
Answered by 7 years ago

Tested and functional; Lengthen the shorten function (haha) to add more values, and update "money" with whatever you desire. Shortens to 1 decimal place.

01local money = 0; -- update this value by whatever means
02local text = script.Parent.Text;
03 
04local shorten = function(number)
05    if(number > 1000 and number < 1000000)then
06        return tostring(math.floor(number/10^2)/10) .. "k";
07    elseif(number > 1000000 and number < 1000000000)then
08        return tostring(math.floor(number/10^5)/10) .. "m";
09    elseif(number > 10^9 and number < 10^12)then
10        return tostring(math.floor(number/10^8)/10) .. "b";
11    -- ... update with more ifs here
12    end
13end
14 
15while wait() do
16    text = shorten(money);
17end
0
It worked with all the other text labels in my game except one which the error says: https://gyazo.com/cd046764742cc7da683f3759346c99c4 the script is: https://gyazo.com/b93bf531466106daaf54073bce2da7c1 PolyyDev 214 — 7y
0
You cannot shorten() the TextLabel's Text. If the Text is shortened to "1K", but you don't gain any money in 1/2 of a second, you will attempt to shorten() tonumber("1K"). tonumber("1K") will return nil, because it is not a number. Therefore, you pass nil into shorten(). You need a separate "money" variable. KidTech101 376 — 7y
Ad
Log in to vote
1
Answered by 7 years ago

You'll need a way to keep track of the actual cash for it wont get lost so just change "Cash" to where you want/are keeping it.

01local value = script.Parent.Text
02local Cash = 50012--Whatever the cash value is
03 
04function changeNumber(int)
05    if tonumber(Cash) > 1000 then
06        print(tostring( Cash/1000 .."k"))
07    end
08end
09 
10while true do
11    changeNumber(value)
12    wait(1)
13end

Answer this question