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

how to put commas in a number when changing the number from a script?

while true do 
	wait(1)
		script.Parent.Text = game.Players.LocalPlayer.Data.Lvl.Value
end

What this script does is show your players level in a gui. Yes I know there is other ways to do this than using while true do, but that is not my problem. I am trying to add commas to it when it updates the text to your level number so kinda like this 1000 is what it normally puts. I want it to say "1,000" so players can read large numbers more easy such as "10,000,000." I have tried various ways and all of them have not worked.

Thank you for reading and if you have any questions about this go ahead and ask.

1 comment

0

use string.format

1 answer

An example from Destrings...

”Let's take "250000" for example, if we use string.gsub("25000", "(%d%d%d)", "%1,") it will return 250,00 because it searches the string from left to right, so we have to reverse it.

string.reverse("25000"):gsub("(%d%d%d)", "%1,") will return "000,52" so we reverse it again to revert the process. string.reverse("25000"):gsub("(%d%d%d)", "%1,") :reverse() and that's it.”

local function addComas(str)
    return #str % 3 == 0 and str:reverse():gsub("(%d%d%d)", "%1,"):reverse():sub(2) or str:reverse():gsub("(%d%d%d)", "%1,"):reverse()
end

print(addComas("250000000"))
print(addComas("25000000"))

3 comments

0

can you give credit to Destrings before copying his scripts and pretty much the entire bottom portion of the answer https://scriptinghelpers.org/questions/14293/how-to-add-commas-in-an-updating-number-value#17305

0

My apologies on his/her name, I had it written as Desi

0

You really say "An example", but you just straight up copied a majority of the answer.

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