Thread Tools Display Modes
10-08-11, 03:06 PM   #1
akgis
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 29
Help with a simple string.format function

I would like to personalize this Shadowed Unit frames function to only show decimal percentage 100.0% if the Unit is under 50%. Example Unit is 100% hp then shows at 100%, unit is under 50% then show 38.7%

function(unit, unitOwner)
local maxHealth = UnitHealthMax(unit)
if( maxHealth <= 0 ) then
return "0.0%"
end

return string.format("%.1f%%", (UnitHealth(unit) / maxHealth) * 100)
end
__________________
  Reply With Quote
10-08-11, 03:27 PM   #2
ALZA
A Deviate Faerie Dragon
 
ALZA's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 19
Code:
function(unit, unitOwner)
	local maxHealth = UnitHealthMax(unit)
	if( maxHealth <= 0 ) then
		return "0.0%"
	end

	local healthPerc = UnitHealth(unit) / maxHealth * 100
	if( healthPerc > 50) then
		return format("%.0f%%", healthPerc)
	else
		return format("%.1f%%", healthPerc)
	end
end
  Reply With Quote
10-08-11, 04:01 PM   #3
akgis
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 29
Originally Posted by ALZA View Post
Code:
function(unit, unitOwner)
	local maxHealth = UnitHealthMax(unit)
	if( maxHealth <= 0 ) then
		return "0.0%"
	end

	local healthPerc = UnitHealth(unit) / maxHealth * 100
	if( healthPerc > 50) then
		return format("%.0f%%", healthPerc)
	else
		return format("%.1f%%", healthPerc)
	end
end
thanks alot
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Help with a simple string.format function


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