- Joined
- Apr 13, 2008
- Messages
- 669
- Reaction score
- 20
This function will format numbers so you can display large ones in a more user-friendly manner. I wrote it to display big bank account balances more neatly.
Usage
The function works fine with both strings and integers. If you don't specify the separator string it will use 'space' by default.
Hope someone finds it usefull
Usage
Code:
formatNum(12345, ",")
> returns 12,345
formatNum(12345)
> returns 12 345
Code:
function formatNum(str, sep)
str = tostring(str):reverse()
str = str:gsub("(%d)(%d)(%d)", '%1%2%3' .. (sep or " "), math.ceil(str:len() / 3)-1)
return str:reverse()
end
Hope someone finds it usefull