Originally Posted by
karvo1023
I know this is a bit old, but I was wondering how to mix both functions into a single one. One where the numbers are abbreviated depending on a specific amount (or several, like the example above), and also compares current health with max health.
If you wanted to format both hp and hpmax you should make double checks (for "k" and "m") for both of them.
Alternatively you could use subfunction to format string and then use it for both hp and hpmax, something like this:
Code:
function ()
local hp = UnitHealth("target")
local hpMax = UnitHealthMax("target")
local function fmt(num)
local n = num
local s = string.format("%.3f", n)
for k,v in pairs {"", "K", "M", "B"} do
n = num/math.pow(1000, k-1)
if n < 1000 and n >= 1 then
s = string.format("%.f%s", n, v)
end
end
return(s)
end
return (fmt(hp).."/"..fmt(hpMax))
end
First string.format controls numbers <1 (3 decimal digits), second string.format controls representation of our new string for >1 numbers (no decimals).
You can control abbreviations (K, M, B, add more if you need) in array.