Quantcast
WoWInterface - View Single Post - code integration
View Single Post
09-25-17, 07:16 PM   #15
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,292
There's also the problem (Edit: as mentioned by Kakjens) with small remainders giving a result of x.00 Mil. so it could be extended too:
Lua Code:
  1. --function for beautiful numbers
  2. local floor = math.floor
  3. local strlen, strsub = string.len, string.sub
  4. local function ReadableNumber(num)
  5.     local ret
  6.     local placeValue = ("%%.%df"):format(2) --probably can be improved into "%.0f"
  7.     local prefix = ""
  8.     if not num then
  9.         return "0 "
  10.     elseif num >= 1000000000000 then
  11.         prefix = " Tril" -- trillion
  12.         if mod(num, 1000000000000) < 10000000000 then
  13.             ret = floor(num / 1000000000000)
  14.         else
  15.             ret = placeValue:format(num / 1000000000000)
  16.         end
  17.     elseif num >= 1000000000 then
  18.         prefix = " Bil" -- billion
  19.         if mod(num, 1000000000) < 10000000 then
  20.             ret = floor(num / 1000000000)
  21.         else
  22.             ret = placeValue:format(num / 1000000000)
  23.         end
  24.     elseif num >= 1000000 then
  25.         prefix = " Mil" -- million
  26.         if mod(num, 1000000) < 10000 then
  27.             ret = floor(num / 1000000)
  28.         else
  29.             ret = placeValue:format(num / 1000000)
  30.         end
  31.     elseif num >= 1000 then
  32.         prefix = "k" -- thousand
  33.         ret = placeValue:format(num / 1000)
  34.     else
  35.         ret = num
  36.     end
  37.     local len = strlen(ret)
  38.     if len > 3 then
  39.         if strsub(ret, len-2, len-2) == "." and strsub(ret, len) == "0" then
  40.             ret = strsub(ret, 1, len-1)
  41.         end
  42.     end
  43.     return ret..prefix
  44. end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-25-17 at 09:54 PM.
  Reply With Quote