formatting numbers

The ability to format numbers for money / time and most importantly the ability to add commas easily to long numbers IE at the thousands, millions, etc.

Fractions may be too much to ask for, but would be great as well.

These would be great if possible. [import]uid: 10903 topic_id: 20301 reply_id: 320301[/import]

Hey, @crssmn, here’s a code snippet I found for formatting numbers with commas. See below.

Naomi

[lua]-- Format numbers (1000 --> 1,000)
– copied from http://lua-users.org/wiki/FormattingNumbers
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[/lua] [import]uid: 67217 topic_id: 20301 reply_id: 79319[/import]

To format currency, try string.format

i.e.

  
print( "$" .. string.format("%05.2f","10") )  
  
-\> $10.00  
  

The “05” is the total number of characters, the “.2” is the number of decimal places, and the “f” forces the number into a float.

As for commas, a quick search brought up this message board thread, but I haven’t tried it with Corona yet:

http://www.gammon.com.au/forum/?id=7805 [import]uid: 120 topic_id: 20301 reply_id: 79352[/import]