Browse Source

Fix poll percentages when 0 votes

Fixes #177
Zed 6 years ago
parent
commit
240a6f9fd3
1 changed files with 2 additions and 1 deletions
  1. 2 1
      src/views/tweet.nim

+ 2 - 1
src/views/tweet.nim

@@ -120,7 +120,8 @@ proc renderPoll(poll: Poll): VNode =
     for i in 0 ..< poll.options.len:
       let
         leader = if poll.leader == i: " leader" else: ""
-        perc = poll.values[i] / poll.votes * 100
+        val = poll.values[i]
+        perc = if val > 0: val / poll.votes * 100 else: 0
         percStr = (&"{perc:>3.0f}").strip(chars={'.'}) & '%'
       tdiv(class=("poll-meter" & leader)):
         span(class="poll-choice-bar", style={width: percStr})