Avoid float conversion when calculating progress

This commit is contained in:
Björn Geuken 2015-05-16 15:19:03 +02:00
parent 5043d26cc5
commit 1862534b2c
2 changed files with 4 additions and 6 deletions

View file

@ -19,13 +19,11 @@ module ApplicationHelper
end
def event_progress_color(progress)
progress = progress.to_i
case progress
case progress.to_i
when 100 then 'progress-bar-success'
when 86 then 'progress-bar-info'
when 85 then 'progress-bar-info'
when 71 then 'progress-bar-warning'
when 14, 29, 43, 57 then 'progress-bar-danger'
when 14, 28, 42, 57 then 'progress-bar-danger'
end
end

View file

@ -211,7 +211,7 @@ class Event < ActiveRecord::Base
def calculate_progress
result = self.progress_status
true_items = result.select { |_key, value| value }.length
(true_items / result.length.to_f * 100).round(0).to_s
(100 * true_items / result.length).to_s
end
private