Thread: Stuf LUA help
View Single Post
11-07-17, 01:27 AM   #12
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
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.
hikokun, while debugging I suggest in line 16 of this code to add print(formatted). And in your code, in line 11 to replace curhp with formatPlayerNumbers(curhp), and maxhp with formatPlayerNumbers(maxhp).

Fizzlemizz, thanks for explanation but I meant to ask what the code accomplishes instead of what it does.

But won't this become unneeded after 7.3.5 with ilvl (and stat) squishes?
  Reply With Quote