File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -265,8 +265,9 @@ def column_for(field)
265
265
def type_cast_calculated_value ( value , column , operation = nil )
266
266
operation = operation . to_s . downcase
267
267
case operation
268
- when 'count' , 'sum' then value . to_i
269
- when 'avg' then value && value . to_f
268
+ when 'count' then value . to_i
269
+ when 'sum' then value =~ /\. / ? value . to_f : value . to_i
270
+ when 'avg' then value && value . to_f
270
271
else column ? column . type_cast ( value ) : value
271
272
end
272
273
end
Original file line number Diff line number Diff line change @@ -102,6 +102,11 @@ def test_should_return_zero_if_sum_conditions_return_nothing
102
102
assert_equal 0 , companies ( :rails_core ) . companies . sum ( :id , :conditions => '1 = 2' )
103
103
end
104
104
105
+ def test_sum_should_return_valid_values_for_decimals
106
+ NumericData . create ( :bank_balance => 19.83 )
107
+ assert_equal 19.83 , NumericData . sum ( :bank_balance )
108
+ end
109
+
105
110
def test_should_group_by_summed_field_with_conditions
106
111
c = Account . sum ( :credit_limit , :conditions => 'firm_id > 1' ,
107
112
:group => :firm_id )
You can’t perform that action at this time.
0 commit comments