Skip to content

Commit

Permalink
If average value from DB is 0, make sure to convert it to a 0.0 float…
Browse files Browse the repository at this point in the history
… before calling #to_d on it [#1346 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
metaskills authored and josh committed Nov 8, 2008
1 parent 1767c4b commit a7f920f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/calculations.rb
Expand Up @@ -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
Expand Down

0 comments on commit a7f920f

Please sign in to comment.