Quantcast
WoWInterface - View Single Post - Stuf LUA help
Thread: Stuf LUA help
View Single Post
11-06-17, 06:02 PM   #10
hikokun
A Murloc Raider
 
hikokun's Avatar
Join Date: Oct 2015
Posts: 4
Originally Posted by Ammako View Post
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 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.
  Reply With Quote