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

how would i add a comma in a money value?

while true do
	wait(1)
	if script.Parent.Value >= 1000 then
		
	elseif script.Parent.Value >= 100000 then

	elseif script.Parent.Value >= 1000000 then

	end
end

i dont know how i would add a comma in the value i would really appreciate it if someone could help me with this. TY

2 comments

0

There is no attempt to make the numbers a comma other than checking if the value >= 1000. Please post the full attempt.

0

i would if i knew how to actually do that im not asking asking you to do the script for me im asking if you have anything that might help me like tell me what i can use or something or link me to wiki that might help me.

1 answer

✓ Accepted answer

Well you could use if statements for every possible number of digits, but why not just use a loop to convert it?

By performing a quick, single google search, I found a simple Lua function that converts numbers to strings with commas.

function comma_value(amount)
	local formatted = amount
	while true do  
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
    		if (k==0) then
      			break
    		end
  	end
	return formatted
end

--[[
print(comma_value(12421143122)) 
> 12,421,143,122
]]--

Hope this helps :)

3 comments

0

thanks bro.

0

what is k on line 4?

0

NVM

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