How to convert integers into a better looking intergers?

Hello, I don’t know exactly how to explain this but. If I have a number for my example: 69420 I want to convert it from that number to a number with commas so I want to change it from 69420 to 69,420. How can I achieve this this is Inside a gui here is my code.

--//local

local plr = game.Players.LocalPlayer
local leaderstat = plr:WaitForChild("leaderstats")
local Tix = leaderstat.Tix

--//main

while wait() do
script.Parent.Text = Tix.Value
end

http://lua-users.org/wiki/FormattingNumbers

edit: more specifically this section

function comma_value(n) -- credit http://richard.warburton.it
	local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
	return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end

I recommend making a function to do that for any number you want

function ConvertInteger(N)
  - code that converts it
  return ConvertedInteger
end

ConvertInteger(Tix.Value)

yikes that looks complicated haha

you will get used to it sooner or later

Just complicated Lua patterns (:
The horrible spacing isn’t helping either, I just copy pasted

im just trying to figure out how to use that code for here like I dont understand the format and where to tell it to convert the certain number

function comma_value(n)
	local left, num, right = string.match(n, '^([^%d]*%d)(%d*)(.-)$')
    local middle = (num:reverse():gsub('(%d%d%d)','%1,'):reverse())
	return left..middle..right
end

that should look a lot cleaner then before

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

this is what i found

let me help you out

--//local

local plr = game.Players.LocalPlayer
local leaderstat = plr:WaitForChild("leaderstats")
local Tix = leaderstat.Tix

--//main

function comma_value(n)
	local left, num, right = string.match(n, '^([^%d]*%d)(%d*)(.-)$')
    local middle = (num:reverse():gsub('(%d%d%d)','%1,'):reverse())
	return left..middle..right
end

while wait() do
script.Parent.Text = comma_value(Tix.Value)
end

alright, I will try that code.

yeah it worked thanks a lot man! and Im gonna look more into complicated lua equations like this.

yw if you need help with anything else tell me

Ok will do thanks for your help!

This is a little of topic to the question, but I noticed something:

I believe this is unoptimized since it repeats over and over.

Value objects have an event called “Changed” that fires when the value of a value object changes.

So I would replace the above code with the code below

Tix.Changed:Connect(function(value)
	script.Parent.Text = comma_value(value)
end)

I think this should work, did not test. Let me know if it doesn’t.

Okay thanks ill take a look into that and revise it thanks!