Search code examples
ruby-on-rails-4averagebigdecimal

averaging numbers in a column in Rails


I have a table with a column of floating point numbers. I want to average the numbers in that column.

Per http://api.rubyonrails.org/classes/ActiveRecord/Calculations.html I used:

Table.average(:column)

What I get is:

#<BigDecimal:7fcacbbe5eb8,'0.4898731422 50531E3',27(36)>

What's the best way to convert that into nearest integer?


Solution

  • Answer to my own question:

    Table.average(:column).round