From 335a31524055c7dd79618ea79b3c18d827e25d3d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 10 Nov 2008 14:16:43 -0600 Subject: [PATCH] Add simple case when DB calculations returns 0 instead of 0.0 [#1346 state:resolved] --- 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 dd90580b3dbf5..6f4e02b430a19 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/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