Display numbers with commas?

Hello!

So, I’m unsure on how to display someone’s points with commas so it’s easy to understand how many digits there are if that kinda makes sense.

So, instead of 9289482395, I would love to see 9,289,482,395.

The current function which displays their points on the scoreboard is


function( ply ) return ply.PS2_Wallet.points end,


What function would I add that would separate the numbers shown by ply.PS2_Wallet.points?

I know that utime has this function which prevents it from being displayed in seconds is:


function timToStr( time )
    local tmp = time
    local s = tmp % 60
    tmp = math.floor( tmp / 60 )
    local m = tmp % 60
    tmp = math.floor( tmp / 60 )
    local h = tmp % 24
    tmp = math.floor( tmp / 24 )
    local d = tmp % 7
    local w = math.floor( tmp / 7 )


    return string.format( "%02iw %id %02ih %02im %02is", w, d, h, m, s )
end


but I can’t figure out how I could possibly convert or reflect from to the display of points.

Thanks for any help.

[editline]12th October 2017[/editline]

Well, I found this http://lua-users.org/wiki/FormattingNumbers but I’m still confused on which suits my case.

string.Comma

[lua]function format_num(amount, decimal, prefix, neg_prefix)
local str_amount, formatted, famount, remain

decimal = decimal or 2 – default 2 decimal places
neg_prefix = neg_prefix or “-” – default negative sign

famount = math.abs(round(amount,decimal))
famount = math.floor(famount)

remain = round(math.abs(amount) - famount, decimal)

    -- comma to separate the thousands

formatted = comma_value(famount)

    -- attach the decimal portion

if (decimal > 0) then
remain = string.sub(tostring(remain),3)
formatted = formatted … “.” … remain …
string.rep(“0”, decimal - string.len(remain))
end

    -- attach prefix string e.g '$' 

formatted = (prefix or “”) … formatted

    -- if value is negative then format accordingly

if (amount<0) then
if (neg_prefix=="()") then
formatted = “(”…formatted …")"
else
formatted = neg_prefix … formatted
end
end

return formatted
end[/lua]

This one?

[editline]12th October 2017[/editline]

Oh wow, xD. Please mark this as “Dumb”. Also Thank you for de help :slight_smile: