WoWInterface - View Single Post - Changing Text Formatting
View Single Post
05-06-17, 10:09 PM   #2
A Pyroguard Emberseer
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,991
Here's what I've started doing with my number displays.
Lua Code:
  1. local math_abs=math.abs;
  2. local math_floor=math.floor;
  3. local math_log10=math.log10;
  4. local math_max=math.max;
  5. local tostring=tostring;
  7. local NumberCaps={"K","M","B","T"};
  8. local function AbbreviateNumber(val)
  9.     local exp=math_max(0,math_floor(math_log10(math_abs(val))));
  10.     if exp<3 then return tostring(math_floor(val)); end
  12.     local factor=math_floor(exp/3);
  13.     local precision=math_max(0,2-exp%3);
  14.     return ((val<0 and "-" or "").."%0."..precision.."f%s"):format(val/1000^factor,NumberCaps[factor] or "e"..(factor*3));
  15. end

It dynamically adjusts the precision based on if the number is in the 1's, 10's, or 100's. It'll revert to scientific notation if the abbreviation accessed is out of the defined scope. You can add more in the NumberCaps table.
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 05-06-17 at 10:18 PM.
  Reply With Quote