decimal point/full number - WoWInterface
03-12-21, 08:54 PM   #1
rulezyx
A Flamescale Wyrmkin

Join Date: Jan 2020
Posts: 106
decimal point/full number

Hello,

I got a code for my raidframes to show health with one decimal point.

Example:

44100 = 44.1k

When the health is under 1k:

910 = 0.9k

But I want it to display the full number when under a thousand so 910 instead of 0.9k.

Can someone help me with this code:
Code:
```hooksecurefunc("CompactUnitFrame_UpdateStatusText",function(self)
if self.optionTable.healthText=="health" and tonumber(self.statusText:GetText() or "") then
local hp = UnitHealth(self.displayedUnit)
local maxhp = UnitHealthMax(self.displayedUnit)
self.statusText:SetText(format("%d%%     %.1fk",hp*100/maxhp,hp/1000))
self.statusText:SetTextColor(0.9,0.9,0.9,1)
if not self.smallStatus then
self.statusText:SetFont("Fonts\\ARIALN.TTF", 14, "THINOUTLINE")
self.smallStatus = false
end
end
end)```

03-12-21, 09:33 PM   #2
Kanegasi
A Molten Giant

Join Date: Apr 2007
Posts: 575
Here you go. I also future-proofed it by formatting higher numbers, if you ever run into that.

Lua Code:
`local function FormatValue(val)    if val<1000 then return ("%.0f"):format(val)    elseif val<1000000 then return ("%.1fk"):format(val/1000)    elseif val<1000000000 then return ("%.1fm"):format(val/1000000)    elseif val<1000000000000 then return ("%.1fb"):format(val/1000000000)    else return ("%.1ft"):format(val/1000000000000) endend hooksecurefunc("CompactUnitFrame_UpdateStatusText",function(self)    if self.optionTable.healthText=="health" and tonumber(self.statusText:GetText() or "") then        local hp=UnitHealth(self.displayedUnit)        local maxhp=UnitHealthMax(self.displayedUnit)        self.statusText:SetText(format("%d%%     %s",hp*100/maxhp,FormatValue(hp)))        self.statusText:SetTextColor(0.9,0.9,0.9,1)        if not self.smallStatus then            self.statusText:SetFont("Fonts\\ARIALN.TTF",14,"THINOUTLINE")            self.smallStatus=false        end    endend)`

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

03-12-21, 10:32 PM   #3
rulezyx
A Flamescale Wyrmkin

Join Date: Jan 2020
Posts: 106
Thank you so much for the fast reply.

I used/ripped similar codes for my weakauras but I still rly have no exact clue how they work (lua format/decimal values).

I tested it out and it showed 658 as 658.000000

I changed %f in line 2 to %s and it seems to work now but I dont know if it interferes with the code itself

03-13-21, 08:13 PM   #4
Seerah
Fishing Trainer

Join Date: Oct 2006
Posts: 10,848
"%.1f" means to format the number as a string with just one floating decimal point. "%.0f" means to format the number with 0 decimal places. I have no idea why you are getting many trailing zeros.

Alternately, you can replace that line with this:
Lua Code:
`if val<1000 then return math.floor(val)`
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

03-13-21, 08:58 PM   #5
Kanegasi
A Molten Giant

Join Date: Apr 2007
Posts: 575
It was originally just %f, but I edited my post after their reply to be %.0f instead.

03-13-21, 11:48 PM   #6
rulezyx
A Flamescale Wyrmkin

Join Date: Jan 2020
Posts: 106
Its working fine now, thank you both so much

 WoWInterface » decimal point/full number

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off