Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to shorten money value 1000000 to 1M?

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

2 comments

0

So is value already 125000 or is it 12.5k?

0

It is 125000

2 answers

✓ Accepted answer

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

2 comments

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

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.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.