Originally Posted by Ammako
This is something I do to format numbers and group into thousands/millions.
lua Code:
local function formatPlayerNumbers(amount) local formatted, k = amount if amount >= 100000 and amount < 100000000 then formatted = string.sub(formatted, 0, (string.len(formatted) - 3)) .. " K" elseif amount >= 100000000 then formatted = string.sub(formatted, 0, (string.len(formatted) - 6)) .. " M" else while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if (k==0) then break end end end return formatted end
Of you're, you'll have to tweak the amounts at lines 4 and 6 to get it to shorten 5,000,000 as 5M rather than 5,000K, but you get the point.
|
I appreciate the code, but how do I incorporate it into my previous code? I've tried a few different ways and all it does is causes the text to disappear.