View Single Post
03-12-21, 09:33 PM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Here you go. I also future-proofed it by formatting higher numbers, if you ever run into that.

Lua Code:
  1. local function FormatValue(val)
  2.     if val<1000 then return ("%.0f"):format(val)
  3.     elseif val<1000000 then return ("%.1fk"):format(val/1000)
  4.     elseif val<1000000000 then return ("%.1fm"):format(val/1000000)
  5.     elseif val<1000000000000 then return ("%.1fb"):format(val/1000000000)
  6.     else return ("%.1ft"):format(val/1000000000000) end
  7. end
  8.  
  9. hooksecurefunc("CompactUnitFrame_UpdateStatusText",function(self)
  10.     if self.optionTable.healthText=="health" and tonumber(self.statusText:GetText() or "") then
  11.         local hp=UnitHealth(self.displayedUnit)
  12.         local maxhp=UnitHealthMax(self.displayedUnit)
  13.         self.statusText:SetText(format("%d%%     %s",hp*100/maxhp,FormatValue(hp)))
  14.         self.statusText:SetTextColor(0.9,0.9,0.9,1)
  15.         if not self.smallStatus then
  16.             self.statusText:SetFont("Fonts\\ARIALN.TTF",14,"THINOUTLINE")
  17.             self.smallStatus=false
  18.         end
  19.     end
  20. end)

Last edited by Kanegasi : 03-13-21 at 01:06 PM. Reason: 0 decimal places for less than 1k
  Reply With Quote