Thread: Stuf LUA help
View Single Post
11-06-17, 05:09 PM   #7
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
This is something I do to format numbers and group into thousands/millions.

lua Code:
  1. local function formatPlayerNumbers(amount)
  2.     local formatted, k = amount
  3.  
  4.     if amount >= 100000 and amount < 100000000 then
  5.         formatted = string.sub(formatted, 0, (string.len(formatted) - 3)) .. " K"
  6.     elseif amount >= 100000000 then
  7.         formatted = string.sub(formatted, 0, (string.len(formatted) - 6)) .. " M"
  8.     else
  9.         while true do  
  10.             formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  11.             if (k==0) then
  12.                 break
  13.             end
  14.         end
  15.     end
  16.  
  17.     return formatted
  18. end

Of course, 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.

Last edited by Ammako : 11-07-17 at 01:46 AM.
  Reply With Quote