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?

local value = script.Parent.Text

function changeNumber(int)
    if tonumber(int) > 1000 then int.Text = 1K
    --// Other stuff
end

while true do
    changeNumber(value)
    wait(1)
end
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.

local money = 0; -- update this value by whatever means
local text = script.Parent.Text;

local shorten = function(number)
    if(number > 1000 and number < 1000000)then
        return tostring(math.floor(number/10^2)/10) .. "k";
    elseif(number > 1000000 and number < 1000000000)then
        return tostring(math.floor(number/10^5)/10) .. "m";
    elseif(number > 10^9 and number < 10^12)then
        return tostring(math.floor(number/10^8)/10) .. "b";
    -- ... update with more ifs here
    end
end

while wait() do
    text = shorten(money);
end
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.

local value = script.Parent.Text
local Cash = 50012--Whatever the cash value is

function changeNumber(int)
    if tonumber(Cash) > 1000 then 
        print(tostring( Cash/1000 .."k"))
    end
end

while true do
    changeNumber(value)
    wait(1)
end

Answer this question