Formatting a number into #,###,###?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Formatting a number into #,###,###?

Post by Jasoco »

vrld wrote:Damnit. I hoped to avoid another gsub. This works, however:

Code: Select all

string.format("%.2f", number):reverse():gsub("(%d%d%d)", "%1,"):reverse():gsub("^,?", "")
Works!
Screen shot 2011-01-07 at 6.37.34 PM.PNG
Screen shot 2011-01-07 at 6.37.34 PM.PNG (22.06 KiB) Viewed 438 times
Thanks again!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 69 guests