method
average
v5.1.7 -
Show latest stable
-
1 note -
Class: ActiveRecord::Calculations
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (-38)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (-5)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (-5)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
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
Register or
log in
to add new notes.
lawitschka -
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.