Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What's The Simplest Way To Add Commas To Numbers > 999?

Asked by 4 years ago

So I have this code:

function addCommas(str)
    return #str % 3 == 0 and str:reverse():gsub("(%d%d%d)", "%1,"):reverse():sub(2) or str:reverse():gsub("(%d%d%d)", "%1,"):reverse()
end

But, that's way to complex for me. I need a way to more simply insert commas into numbers above 999.

0
it works just fine dude idk what you're talking about this Fifkee 2017 — 4y
0
literally just call the function using addComas(number) Fifkee 2017 — 4y
0
Could get the length then scan through the original number, adding a comma in the desired position alphawolvess 1784 — 4y
0
wait, so you're saying i could just get the length of the number, then add a comma in every 3rd number? AlphaWolf536791 28 — 4y
0
yes Fifkee 2017 — 4y

Answer this question