So I’ve been trying to add commas for every 3 numbers for my game and I’ve tried looking for solutions on the DevForum. I found thispost but it didn’t seem to work for me for some reason.
This is all in a local script
local function format_number(v)
return tostring(v):reverse():gsub("%d%d%d", "%1", (#tostring(v) - 1) / 3):reverse()
end
money:GetPropertyChangedSignal("Value"):Connect(function()
MoneyUiText.Text = "$".. format_number(money.Value)
end)
Even though this seemed like it was going to work, it didn’t for some reason. Also when I’m in the script editor I keep seeing this orange line beneath the “%1”.
So I reloaded studio, opened the script and the line was gone so I retried playing the game but it didn’t work. I then tried your method and tried using “%i” but it also gave a line…
This is string.gsub replacement string format. You are talking about string.format format specifier.
To OP: You didn’t include the separator (,) are the end of the replacement string.
I’d change %1 to %0 for matching entire pattern for replacement string argument on string.gsub as %1 emits a warning for this even though it is valid (IIRC someone said somewhere on the forum that this is intentional but I can’t find it now and don’t quote me on that).