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

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

Asked by 6 years ago

This question already has an answer here:

How to add comma's in an updating number value?
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.

0
use string.format User#23365 30 — 6y

Marked as Duplicate by Shawnyg

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
ABK2017 406 Moderation Voter
6 years ago
Edited 6 years ago

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"))
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 User#19524 175 — 6y
0
My apologies on his/her name, I had it written as Desi ABK2017 406 — 6y
0
You really say "An example", but you just straight up copied a majority of the answer. Shawnyg 4330 — 6y
Ad