• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Function to format numbers

nsanee

Member
Senator
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
Code:
formatNum(12345, ",")
> returns 12,345
formatNum(12345)
> returns 12 345
The function works fine with both strings and integers. If you don't specify the separator string it will use 'space' by default.

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 :)
 
Thanks :)

lol Chojrak you're sure alert - you posted 1 minute after I submitted this :)
 
Hmm, functiontastic!

Is Chojrak back? :eek:
 
Back
Top