Permalink
Browse files

Add simple case when DB calculations returns 0 instead of 0.0 [#1346

…state:resolved]
  • Loading branch information...
1 parent a6d6a1c commit 335a31524055c7dd79618ea79b3c18d827e25d3d @josh josh committed Nov 10, 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_f.to_d
+ when 'avg' then value && (value == 0 ? 0.0.to_d : value.to_d)
else type_cast_using_column(value, column)
end
end

0 comments on commit 335a315

Please sign in to comment.