Flowdock
average(column_name) public

Calculates the average value on a given column. Returns nil if there’s no row. See #calculate for examples with options.

Person.average(:age) # => 35.8
Show source
Register or log in to add new notes.
February 15, 2011 - (v3.0.0)
0 thanks

No type cast to Float

In Rails 3 the returned value will be type cast to the column’s type and not Float. So when calculating average on a column the column’s type need to be float, the result will be truncated otherwise.