aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/calculations.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb
index 889b7845fb..caa8c539d5 100644
--- a/activerecord/lib/active_record/calculations.rb
+++ b/activerecord/lib/active_record/calculations.rb
@@ -265,8 +265,9 @@ module ActiveRecord
def type_cast_calculated_value(value, column, operation = nil)
operation = operation.to_s.downcase
case operation
- when 'count', 'sum' then value.to_i
- when 'avg' then value && value.to_f
+ when 'count' then value.to_i
+ when 'sum' then value =~ /\./ ? value.to_f : value.to_i
+ when 'avg' then value && value.to_f
else column ? column.type_cast(value) : value
end
end