liquid_feedback_frontend
changeset 167:1fdf1e607494
fix vote count display in corner cases
if number of voters are 0 or votes are 0 don't show percentes they are useless or -nan :-)
if number of voters are 0 or votes are 0 don't show percentes they are useless or -nan :-)
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Sat Oct 09 21:34:25 2010 +0200 (2010-10-09) |
parents | ab0149f40b75 |
children | 1783a0c61734 |
files | app/main/initiative/_show.lua |
line diff
1.1 --- a/app/main/initiative/_show.lua Sat Oct 09 21:13:30 2010 +0200 1.2 +++ b/app/main/initiative/_show.lua Sat Oct 09 21:34:25 2010 +0200 1.3 @@ -13,11 +13,15 @@ 1.4 local positive_votes = initiative.positive_votes 1.5 local negative_votes = initiative.negative_votes 1.6 local sum_votes = initiative.positive_votes + initiative.negative_votes 1.7 - slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. " (" .. string.format("%.f", positive_votes * 100 / sum_votes ) .. "%)" .. "</b>") 1.8 + local function perc(votes, sum) 1.9 + if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end 1.10 + return "" 1.11 + end 1.12 + slot.put(_"Yes" .. ": <b>" .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "</b>") 1.13 slot.put(" · ") 1.14 slot.put(_"Abstention" .. ": <b>" .. tostring(max_value - initiative.negative_votes - initiative.positive_votes) .. "</b>") 1.15 slot.put(" · ") 1.16 - slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. " (" .. string.format( "%.f", negative_votes * 100 / sum_votes ) .. "%)" .. "</b>") 1.17 + slot.put(_"No" .. ": <b>" .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "</b>") 1.18 slot.put(" · ") 1.19 slot.put("<b>") 1.20 if initiative.rank == 1 then