Permalink
Browse files

If average value from DB is 0, make sure to convert it to a 0.0 float…

… before calling #to_d on it [#1346 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
1 parent 1767c4b commit a7f920f674d234f281d2491ebe6d74710a79e663 @metaskills metaskills committed with josh Nov 8, 2008
Showing with 1 addition and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/calculations.rb
@@ -286,7 +286,7 @@ def type_cast_calculated_value(value, column, operation = nil)
case operation
when 'count' then value.to_i
when 'sum' then type_cast_using_column(value || '0', column)
- when 'avg' then value && value.to_d
+ when 'avg' then value && value.to_f.to_d
else type_cast_using_column(value, column)
end
end

0 comments on commit a7f920f

Please sign in to comment.