修改了分母不能为0的bug

统计结果精确到两位
Poll
huang 11 years ago
parent 2cbe801528
commit 59c21d81e9

@ -50,7 +50,9 @@ module PollHelper
#统计答题百分比 #统计答题百分比
def statistics_result_percentage(e, t) def statistics_result_percentage(e, t)
return e*100/t e = e.to_f
t = t.to_f
t == 0 ? 0 : format("%.2f", e*100/t)
end end
def options_show p def options_show p

@ -1,38 +1,33 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%= l(:label_poll_result) %></title> <title><%= l(:label_poll_result) %></title>
<%= stylesheet_link_tag 'polls', :media => 'all' %> <%= stylesheet_link_tag 'polls', :media => 'all' %>
</head> </head>
<body>
<body> <div class="polls_content polls_box" id="polls">
<div class="polls_content polls_box" id="polls"> <div class="ur_page_head" >
<div class="ur_page_head" > <h1 class="ur_page_title"><%= @poll.polls_name %> <%= l(:label_poll) %></h1>
<h1 class="ur_page_title"><%= @poll.polls_name %> <%= l(:label_poll) %></h1> </div>
</div> <% @poll_questions.each do |poll_question| %>
<div class="">
<% @poll_questions.each do |poll_question| %> <ol>
<div class=""> <li class="ur_question_item">
<ol> <div class="ur_title_result">
<li class="ur_question_item"> <span class="title_index">第<%= poll_question.question_number %>题:</span><%= poll_question.question_title %> <span class="title_index">[<%= options_show(poll_question.question_type) %>]</span>
<div class="ur_title_result"> </div>
<span class="title_index">第<%= poll_question.question_number %>题:</span><%= poll_question.question_title %> <%= render :partial =>'choice_show', :locals =>{ :poll_question => poll_question } %>
<span class="title_index">[<%= options_show(poll_question.question_type) %>]</span> </li>
</div> </ol>
<%= render :partial =>'choice_show', :locals =>{ :poll_question => poll_question } %> <% end %>
</li> <ul class="wlist">
</ol> <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
<% end %> </ul>
<ul class="wlist"> <div class="cl"></div>
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> <div class="ur_buttons"></div>
</ul> <div class="cl"></div>
<div class="cl"></div> </div>
<div class="ur_buttons"> </div>
</div> </body>
<div class="cl"></div>
</div>
</div><!--问卷内容end-->
</body>
</html> </html>

Loading…
Cancel
Save