Format integer 1000000 to 1.000.000

Hello there,

I’m a beginner to Lua and dont really understand how I can format the string or integer let’s say 1000000 in a way that it returns 1.000.000

is that very hard to do? I’m not shure if I can do it with format function and the printf parameters…

any help appreciated,
Roman [import]uid: 140000 topic_id: 30797 reply_id: 330797[/import]

Jonathan Beebe has provided a great lua library beebegames.lua, and in it is a function to format thousands with commas :

function commaThousands(amount)  
 amount = tonumber(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  
  

That should do the trick. [import]uid: 87794 topic_id: 30797 reply_id: 123277[/import]

Thank you sir,

I really appreciate your help. Works like a charm [import]uid: 140000 topic_id: 30797 reply_id: 123289[/import]

Jonathan Beebe has provided a great lua library beebegames.lua, and in it is a function to format thousands with commas :

function commaThousands(amount)  
 amount = tonumber(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  
  

That should do the trick. [import]uid: 87794 topic_id: 30797 reply_id: 123277[/import]

Thank you sir,

I really appreciate your help. Works like a charm [import]uid: 140000 topic_id: 30797 reply_id: 123289[/import]