From a7f920f674d234f281d2491ebe6d74710a79e663 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Fri, 7 Nov 2008 20:39:06 -0600 Subject: 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 --- activerecord/lib/active_record/calculations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index 5e33cf1bd4..dd90580b3d 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -286,7 +286,7 @@ module ActiveRecord 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 -- cgit v1.2.3