# HG changeset patch # User Daniel Poelzleithner # Date 1286652865 -7200 # Node ID 1fdf1e60749439a7279119b1e185f09f09cb29bd # Parent ab0149f40b750c51823002711d7cdef9648d18e0 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 :-) diff -r ab0149f40b75 -r 1fdf1e607494 app/main/initiative/_show.lua --- a/app/main/initiative/_show.lua Sat Oct 09 21:13:30 2010 +0200 +++ b/app/main/initiative/_show.lua Sat Oct 09 21:34:25 2010 +0200 @@ -13,11 +13,15 @@ local positive_votes = initiative.positive_votes local negative_votes = initiative.negative_votes local sum_votes = initiative.positive_votes + initiative.negative_votes - slot.put(_"Yes" .. ": " .. tostring(positive_votes) .. " (" .. string.format("%.f", positive_votes * 100 / sum_votes ) .. "%)" .. "") + local function perc(votes, sum) + if sum > 0 and votes > 0 then return " (" .. string.format( "%.f", votes * 100 / sum ) .. "%)" end + return "" + end + slot.put(_"Yes" .. ": " .. tostring(positive_votes) .. perc(positive_votes, sum_votes) .. "") slot.put(" · ") slot.put(_"Abstention" .. ": " .. tostring(max_value - initiative.negative_votes - initiative.positive_votes) .. "") slot.put(" · ") - slot.put(_"No" .. ": " .. tostring(initiative.negative_votes) .. " (" .. string.format( "%.f", negative_votes * 100 / sum_votes ) .. "%)" .. "") + slot.put(_"No" .. ": " .. tostring(initiative.negative_votes) .. perc(negative_votes, sum_votes) .. "") slot.put(" · ") slot.put("") if initiative.rank == 1 then